如何用Sails-mongo按id选择文件? [英] How to select document by id with Sails-mongo?
本文介绍了如何用Sails-mongo按id选择文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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")
}
此代码不起作用,我想通过Id选择文档。我不知道在我的帆项目中应该怎么做才能解决这个问题。谢谢你的帮助。
This Code doesn't work, I would like to select document by Id. I don't know what I should do to fix that in my sails project. Thank you for your help.
推荐答案
我看到的一些事情对你的代码很奇怪。
1.应该使用.exec()
来执行与风帆10相关的回调函数。我认为你不应该搜索 _id
但仅限于 ID
。我认为waterline解析了这个下划线。
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
});
});
这篇关于如何用Sails-mongo按id选择文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文