I have a MongoDb ATLAS database as "BOULDERS_MAIN" and a collection inside it "users", I am writing a webhook function for returning a user based on email i.e. "kb", but all I'm getting is empty object.
Asked
Active
Viewed 156 times
1 Answers
1
MongoDB's find()
returns a cursor object not the results. Try calling toArray() on the result instead:
var doc = users.find({email: 'kb'}).toArray();

dnickless
- 10,733
- 1
- 19
- 34
-
Thanks @dnickless, additionally we can use : var doc = users.findOne({email: 'kb'}); – Kushal Bhalaik Oct 16 '18 at 04:44
-
@kushal: Yes, totally, if you only want to get one item. The `email: 'kb'` filter seemed to imply that there might be more matches... – dnickless Oct 16 '18 at 06:59