Sunday, 18 August 2013

MongoDB: How to find key by value

MongoDB: How to find key by value

I'm using Node.js with express framework and Mongoose (MongoDB), and I
have a question about how to effectively retrieve data.
Let's say I have something like this on a mongo document:
test : {a:1, b:2, c:2, d:1};
It's easy to retrieve the value of keys (a,b,c, or d), but how to do the
inverse, for example retrieve all the letters that have value 2 (in my
example it would be 'b' and 'c')
Thanks!

No comments:

Post a Comment