mongodb嵌套对象ID
嗨,我正在尝试构建一个社交应用程序,用户可以互相关注我的用户模式如下:
{
_id: ObjectId('62b6a1ad5bb65d5a1e2c0dcc'),
name: 'Admin',
username: 'Admin',
email: '[email protected]',
password: '$2b$10$qVWp8HZdId/cjVOXwiNLyeyv0jNo7BMFqFEKwNQniusazABp6s216',
profilePicture: '',
coverPicture: '',
followers: [
ObjectId('62b6abc96e3985aa5b2848b8'),
ObjectId('62b6abb96e3985aa5b2848b0'),
ObjectId('62b6abbf6e3985aa5b2848b2'),
],
following: [],
isAdmin: false,
createdAt: 2022-06-25T05:48:29.095Z,
updatedAt: 2022-06-25T07:45:33.290Z,
__v: 0,
}
post架模式
{
_id: ObjectId('62b6eaba03ca17b3eb642e24'),
userId: ObjectId('62b6a1ad5bb65d5a1e2c0dcc'),
description: 'one',
image:'https://firebasestorage.googleapis.com/v0......',
tags: [],
likes: [],
createdAt: '2022-06-25T11:00:10.108Z',
updatedAt: '2022-06-25T11:00:10.108Z',
__v: 0,
}
关注者,跟随,喜欢的是ObjectID的数组。 我想为用户获取时间轴帖子,其中包括该用户的帖子和他的以下帖子。在Nodejs服务器中,如果没有RunInng循环,我如何实现此结果。
Hi I am trying to build a social app where user can follow each other my user schema looks like this :
{
_id: ObjectId('62b6a1ad5bb65d5a1e2c0dcc'),
name: 'Admin',
username: 'Admin',
email: '[email protected]',
password: '$2b$10$qVWp8HZdId/cjVOXwiNLyeyv0jNo7BMFqFEKwNQniusazABp6s216',
profilePicture: '',
coverPicture: '',
followers: [
ObjectId('62b6abc96e3985aa5b2848b8'),
ObjectId('62b6abb96e3985aa5b2848b0'),
ObjectId('62b6abbf6e3985aa5b2848b2'),
],
following: [],
isAdmin: false,
createdAt: 2022-06-25T05:48:29.095Z,
updatedAt: 2022-06-25T07:45:33.290Z,
__v: 0,
}
Post schema
{
_id: ObjectId('62b6eaba03ca17b3eb642e24'),
userId: ObjectId('62b6a1ad5bb65d5a1e2c0dcc'),
description: 'one',
image:'https://firebasestorage.googleapis.com/v0......',
tags: [],
likes: [],
createdAt: '2022-06-25T11:00:10.108Z',
updatedAt: '2022-06-25T11:00:10.108Z',
__v: 0,
}
Followers , Following , likes are the array of objectId .
I want to fetch timeline post for user it include the post of that users and post of his following . How I can achive this result without runinng loops in the nodejs server .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
$查找
获得匹配的帖子结果将添加到字段中,然后跟随post
尝试 Playground
use
$lookup
for get matched postthe result will be added to field my-post and follow-post
try playground