【发布时间】:2013-08-12 21:41:01
【问题描述】:
我想通过这样的cookie查询用户
User.findById(req.signedCookies.userid,
然后在用户中的一个数组中查询另一个用户ID。
数组是friendRequest,我正在查询另一个用户的ID。然后我想根据用户的 id 是否存在返回 true 或 false。
这是为 mongoDB 准备的。 (我在 node.js 中使用猫鼬)
【问题讨论】:
我想通过这样的cookie查询用户
User.findById(req.signedCookies.userid,
然后在用户中的一个数组中查询另一个用户ID。
数组是friendRequest,我正在查询另一个用户的ID。然后我想根据用户的 id 是否存在返回 true 或 false。
这是为 mongoDB 准备的。 (我在 node.js 中使用猫鼬)
【问题讨论】:
检查用户是否存在的查询是
User.find({_id: req.signedCookies.userid,friendRequest:friendRequesId})
这只会在用户匹配并且包含匹配的朋友请求时返回结果
例子
> db.t.insert({id: 1, users:[2,3,4]})
> db.t.findOne({id:1, users: 2})
【讨论】: