Javascript 在Mongo shell中更新int数组转换为双数组
我在集合中使用MongoShell更新int数组。当我更新它时,它实际上以双格式存储Javascript 在Mongo shell中更新int数组转换为双数组,javascript,mongodb,mongo-shell,Javascript,Mongodb,Mongo Shell,我在集合中使用MongoShell更新int数组。当我更新它时,它实际上以双格式存储 var array =[1,2,3]; // int array as all elements are int // Update query where path is the collection field db.doc.update({},{$set : {“path”:array}},{ upsert: true }); 实际上它
var array =[1,2,3]; // int array as all elements are int
// Update query where path is the collection field
db.doc.update({},{$set : {“path”:array}},{ upsert: true });
实际上它存储了:
{
"_id" : ObjectId("529ae0e70971d81eedf5cb3d"),
"path" : [1.0, 2.0, 3.0]
}
我是mongo的新手,必须在mongo shell中运行更新查询。如何避免自动双转换 默认情况下,Mongoshell将数字视为浮点数。所以,如果你想把它们当作别的东西来对待,请明确地告诉mongo。对于您的情况,您必须使用 所以
var数组=[NumberInt(“1”)、NumberInt(“2”)、NumberInt(“3”)代码>
顺便说一句,你可能会发现我的(与之类似)也很有帮助