Newbie: Using $mod method during insert in mongodb

30 views Asked by At

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.

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}) }

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

1

There are 1 answers

0
Jai Hirsch On BEST ANSWER

The $mod operator is used for queries and projection.

https://docs.mongodb.com/manual/reference/operator/query/mod/

For your javascript function use the language specific operator for insertion:

for (i=1; i<=10; i++) { db.aggtest.insert( {a : i%3, b : i}) }