我尝试使用
db.orders.insert({"Price":NumberDecimal("12.34")})
它会抛出此错误
Node.js中的 "ReferenceError: NumberDecimal is not defined"
但它在robo3T中运行良好
db.getCollection('orders').insert({"Price":NumberDecimal("12.34")})
MongoDB shell版本:v3.4.7
MongoDB服务器版本:3.4.7
答案 0 :(得分:1)
将mongodb.Decimal128.fromString('12.34')
替换为Traceback (most recent call last):
File "/home/himanshu/ML Tut-2/ML_tut2.py", line 13, in <module>
knn.fit(X_train, y_train)
File "/usr/local/lib/python2.7/dist-packages/sklearn/neighbors/base.py", line 765, in fit
X, y = check_X_y(X, y, "csr", multi_output=True)
File "/usr/local/lib/python2.7/dist-packages/sklearn/utils/validation.py", line 542, in check_X_y
ensure_min_features, warn_on_dtype, estimator)
File "/usr/local/lib/python2.7/dist-packages/sklearn/utils/validation.py", line 402, in check_array
array = np.array(array, dtype=dtype, order=order, copy=copy)
ValueError: invalid literal for float(): 72%
答案 1 :(得分:1)
您无需在NodeJS中编写NumberDecimal 撰写时
db.orders.insert({"Price":NumberDecimal("12.34")})
您可以将上述查询写为
var price= parseFloat("12.34");
db.orders.insert({"Price" : price})
如果您正在使用猫鼬模式,则可以定义结构的数据类型,并且在插入时,mongo将自动采用相关的数据类型,因为您已经在猫鼬模式中定义了