so I'm doing a mongoose find and I've defined collections etc and it all works fine EXCEPT when I try to do a find by a value.
var searchID = req.user.id;
console.log(searchID);
Locations.find({userid: '541f69e7fd4c3b07108c92c0'}, function(err, location) {
if (err) return console.error(err);
console.log(location);
});
the userid is a property which is the ID of the user that created it. The find doesnt work in mongo console either.
Any ideas? I can do finds by the actual _id of the location or any other value.
As Neil Lunn commented, your problem is almost certainly your schema not being correct. Once your mongoose schema clearly defines the userid property as being of type mongoose.Schema.Types.ObjectId, mongoose will start casting your string value from the query to a proper ObjectId instance before sending it to mongodb, and thus the query will start matching documents and you'll see results.
{userid: {type: mongoose.Schema.Types.ObjectId, ref: 'Users'}}