【发布时间】:2020-03-28 01:10:15
【问题描述】:
我是 mongoDB 的新手,在编写查询时遇到了一些困难。
对于给定的用户,我需要找到他尚未关注的用户。
{
_id:1,
username:"user1",
follows:[2,3]
},
{
_id:2,
username:"user2",
follows:[3]
},
{
_id:3,
username:"user3",
follows:[1]
},
{
_id:4,
username:"user4",
follows:[2,1]
},
{
_id:5,
username:"user5",
follows:[3]
}
请注意,follows 字段包含 _id 的用户,我们的特定用户正在关注这些用户。
我需要编写一个查询,为我提供用户未关注的所有用户的列表。
就像用户 1 不关注用户 4 和用户 5
所以对于 user1,我的输出将是:-
{
_id:4,
username:"user4",
follows:[2,1]
},
{
_id:5,
username:"user5",
follows:[3]
}
【问题讨论】:
标签: mongodb mongoose mongodb-query mongodb-atlas