User.find({ _id: { \'!\': user.id } }, function foundFriends (err, friends) {
if(err) return next(err);
res.view({
friends: friends
});
}
There are couple of things I see are weird with your code.
1. The callback function as for sails 10 should be executed with .exec()
2. I think you should not search for _id
but only id
. I think waterline parses this underscore.
Having that in mind your code should look something like
User.find({ id: { '!': user.id } }).exec(function (err, friends) {
if(err) return next(err);
res.view({
friends: friends
});
});
You can try this:
User.findOne({ _id : ObjectId(user.id.toString()) })
Hope this help.
Hi you can try this for find, update, or destroy by id with sails-mongo via select
:
//Schema
module.exports = {
autoPK : false,
attributes : {
id : {
type: 'string',
primaryKey: true
},
name : {
type : 'string'
},
email : {
type : 'string'
}
}
}
// Find
User.find({
select : {id : user.id}
}).exec((err,record)=> {
if(err) return console.log(err,"err");
console.log(record,"record");
})
// Update
User.update({
select : {id : user.id}
},{
name : "Foo"
}).exec((err,record)=> {
if(err) return console.log(err,"err");
console.log(record,"record");
})
// Destroy
User.destroy({
select : {id : user.id}
}).exec((err,record)=> {
if(err) return console.log(err,"err");
console.log(record,"record");
})
Hope this can help to you.