I'm using Waterline in my Sails.js app, with the sails-mongo adapter. I'm trying to get a record from my MongoDB searching by _id
. This is what I've tried:
Case.findOne({id: args.itemId}).exec(function(err, retObj) {...}
Case.findOne({_id: args.itemId}).exec(function(err, retObj) {...}
Case.findOne({_id: { 'contains': args.itemId} }).exec(function(err, retObj) {...}
Case.findOne({_id: { 'like': '%' + args.itemId} }).exec(function(err, retObj) {...}
and none of those return an object. The only thing I've found that returns an object is:
Case.findOne({_id: { '!': args.itemId} }).exec(function(err, retObj) {...}
which I found in this StackOverlow answer. But...that is the not
operator. So while it worked when I only had one record in the collection, it doesn't return the correct object. I'm not sure why it even worked at all when there was one object in the collection to begin with.
What do I need to do to get an object by its ID with sails-mongo?