I'm having troubles using the MongoDB findOne() function together with mongoose.
controller
exports.show = function (req, res) {
Fahrt.load(req.params.fahrtenId, function (err, fahrt) {
res.jsonp(fahrt);
});
};
model
FahrtSchema.statics = {
load: function (id, cb) {
this.findOne({
_id: id
}
).exec(cb);
}};
route
router.get('/:fahrtId', fahrtenController.show);
app.js
app.use('/fahrten', fahrten);
When I use Postman to query for a "Fahrt"Object with a specific ID I get back "null". When I search with the Mongo Console directly via
db.Fahrt.findOne({"_id": ObjectId("5562ca06a14c4924090ba5ff")})
I get an existing object and everything is as expected. But why not when I query via Mongoose?