[英]Newbie: Using $mod method during insert in mongodb
I'm sure this is the easiest question for you, but forgive me for being naive. 我相信这对您来说是最简单的问题,但请原谅我天真。 I have been trying to learn mongodb and wanted to experiment with some aggregation.
我一直在尝试学习mongodb,并想尝试一些聚合。
For that, I wanted to insert data into a collection like this. 为此,我想将数据插入这样的集合中。
for (i=1; i<=10; i++) { db.aggtest.insert( {a : { $mod: [i, 3]}, b : i}) } 对于(i = 1; i <= 10; i ++){db.aggtest.insert({a:{$ mod:[i,3]},b:i})}}
However this doesn't seem to work. 但是,这似乎不起作用。 I have tried using it for update as well, but it gives a different error for me.
我也尝试过使用它进行更新,但是它给我带来了另一个错误。
Please help me with this. 请帮我解决一下这个。
Thanks Radha 谢谢拉达
The $mod operator is used for queries and projection. $ mod运算符用于查询和投影。
https://docs.mongodb.com/manual/reference/operator/query/mod/ https://docs.mongodb.com/manual/reference/operator/query/mod/
For your javascript function use the language specific operator for insertion: 对于您的javascript函数,请使用语言特定的运算符进行插入:
for (i=1; i<=10; i++) { db.aggtest.insert( {a : i%3, b : i}) }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.