admin管理员组文章数量:1391960
I have int array to update in collection using mongo shell .When I update it actually it stores in double format .
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 });
Actually it stored:
{
"_id" : ObjectId("529ae0e70971d81eedf5cb3d"),
"path" : [1.0, 2.0, 3.0]
}
I am novice to mongo and have to run update query in mongo shell. How to avoid auto double conversion.
I have int array to update in collection using mongo shell .When I update it actually it stores in double format .
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 });
Actually it stored:
{
"_id" : ObjectId("529ae0e70971d81eedf5cb3d"),
"path" : [1.0, 2.0, 3.0]
}
I am novice to mongo and have to run update query in mongo shell. How to avoid auto double conversion.
Share Improve this question asked Dec 1, 2013 at 7:23 Sumeet Kumar YadavSumeet Kumar Yadav 13k6 gold badges50 silver badges87 bronze badges 01 Answer
Reset to default 8Mongoshell treats numbers as float by default. So if you want them to be treated as something else, tell this to mongo explicitly. For your case, you have to use NumberInt().
So var array = [NumberInt("1"), NumberInt("2"), NumberInt("3")];
P.S. you might find my another answer (which is similar) helpful as well.
本文标签: javascriptUpdating int array gets converted to double array in Mongo shellStack Overflow
版权声明:本文标题:javascript - Updating int array gets converted to double array in Mongo shell - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744686644a2619742.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论