U
U
Urukhayy2017-01-15 13:49:20
JavaScript
Urukhayy, 2017-01-15 13:49:20

How to search by _Id in mongoose (mongodb)?

With a search like this:

Model.find({_id: "587b52b71b3e0e1c05dfc80d"}, (err, res) => {
    console.log(res);
})

Returns "undefined". This _id exists in the database. The _id field is created by default.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Gray, 2017-01-26
@theobroma

I have so:

User.find({ "username": identifier }).then((data) => {
       console.log(data);
  });

"User" - mongoose model; "username" - field in the database; identifier - value for username, taken from req.body.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question