Can't get mongoose findById() working -


from mongo shell

db.messages.find({_id:objectid('57b12ca68ea2e15c182044f3')}) 

works , prints record screen.

from express http://localhost:3000/messages/57b12ca68ea2e15c182044f3

app.get('/messages/:id', function (req, res) {   console.log('searching user id: ' + req.params.id);    // message null, have tried without "mongoose.types.objectid" still null   message.findbyid(mongoose.types.objectid(req.params.id), function(err, message) {     console.log('found record');      res.setheader('content-type', 'application/json');     res.send(json.stringify(message));   }); }); 

i null response every time. have tried without using objectid wrapper still null values. mongodb connection fine because have message.find({}, function(err, messages) { ... } returns messages successfully.

what doing wrong?

turns out incorrectly defined _id: string in mongoose schema file caused issue. removing _id definition solves this.


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -