I am trying to get a list of books with their copyright information.
Some users have been deleted, and therefore they no longer have the db document, so their information is null.
I try to pull out books ONLY if their creators still exist.
This is my code:
Book.find({_creator:{$ne:null}}).populate( { path: '_creator', match: { _id: { $ne: null }} }) .exec(function (err,books) { if(err) throw err; if(books) { res.send(books) } })
This is what it returns:
[ { "_id":"55d98e6a4de71010099c59eb", "dateOfCreation":"2015-08-23T09:12:10.095Z", "_creator":null, "__v":0, "coverUrl":"cover14403211323926quv.png", "description":"asdasd", "name":"asdasd" } ]
Note that the _creator field is null. Why is this?
source share