如何使用Sails-mongoselectid文件?

User.find({ _id: { '!': user.id } }, function foundFriends (err, friends) { if(err) return next(err); res.view({ friends: friends }); }); MONGODB : { _id: ObjectId("53b942f7c8638f7b17670acc"), name: "PH", admin: true, online: false, encryptedPassword: "$2a$10$PjcPRgL67ZSOWDjmEwTkvu30xKeDXdCwgZ.D0.bjyDRw9sOfS/4UK", createdAt: ISODate("2014-07-06T12:37:11.522Z"), updatedAt: ISODate("2014-07-09T18:22:47.25Z") } 

此代码不起作用,我想通过Idselect文档。 我不知道该怎么做才能解决这个问题。 感谢您的帮助。

有几件事我看到你的代码很奇怪。
1.对于风帆10的callback函数应该用.exec()
我认为你不应该search_id而只能searchid 。 我认为水线parsing这个下划线。

考虑到你的代码应该看起来像这样

 User.find({ id: { '!': user.id } }).exec(function (err, friends) { if(err) return next(err); res.view({ friends: friends }); }); 

嗨,你可以尝试这个查找,更新,或通过select与sails-mongo通过ID销毁:

  //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"); }) 

希望这可以帮助你。