mongoosejs/mquery

Query On Using Mod in MQuery

Closed this issue · 4 comments

Hi Heckmann

I have been sourcing for information on how to do the following in mongo but always fail till I saw your git.
Data (data format: id, price, flag)
id_1, 11, false
id_2, 22, false
id_3, 33, false,
id_4. 44. false
id_5, 55. false.
id_6, 66. false

I am using TS and will like even row be flag as true. How can I do it using mquery. Can help? Thank

Can you please clarify your question? I don't understand.

@ybchoo If I understand correctly, what you want is to update flag to true when price is even (mod 2 equals to 0)

You can do this:

mquery().where('price').mod([2,0]).update({$set: { flag: true }})
  .setOptions({ multi: true }).exec(callback)

you can use all of the following syntax

  • where('price').mod([2,0])
  • where('price').mod(2, 0)
  • mod('price', [2, 0])
  • mod('price', 2, 0)