如何使用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"); })
希望这可以帮助你。
- 使用ES6的Promise.all()时限制并发的最好方法是什么?
- 为什么Javascript map函数String.toLowerCase在nodejs 6中不起作用?
- (Angularjs)Web应用程序的集成testing
- 监听单个快速应用程序的HTTP和HTTPS
- CommonJS为什么不要求函数asynchronous?
- 使用邮件传输的Node.js winston日志logging只发送uncaughtException作为电子邮件
- ImageMagick比较:从Node.js生成时退出代码1,但从命令行运行时退出代码0
- 身份validationExpressJS – > passportJs:错误:发送后无法设置标头
- 严格的平等是否保证了平等