I was learning some mongodb stuff, and it's pretty awesome!
I decided to try it out with mongoose in node and came upon the realization that I have no idea how to run an or command, so I looked up how you would do an or command in regular mongoose and found that the query is similar to this:
db.meh.find({ $or : [ { a : 3 }, { b : 4 } ] });
And that seems to work great with the command line program for finding all entities where a == 3 or b == 4
But... How would I do this in mongoose?
Any help is appreciated!!
Note I also would like to be able to do this with the findOne() method, but I'm assuming that it'll act just the same as find() with a limit on it
It should be the same in mongoose.
SomeObjects.find({$or : [{a: 3}, {b: 4}]});
Note I also would like to be able to do this with the findOne() method, but I'm assuming that it'll act just the same as find() with a limit on it
Yea, that should work as well.
i don't think you need to find anything here as mongoose has helpers for that (not sure if this was the case at the time of the post though):
query.or([{ color: 'blue' }, { color: 'red' }]);
mongoose query doc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With