猫鼬来自许多集合

问题描述

我想从多个集合中填充,然后按日期对其进行排序并将所有数据收集到一个数组中。 到目前为止,我有这个

 await User.findById(req.user._id)
  .populate([
    { path: 'posts.collection1',select,limit: LIMIT },{ path: 'posts.collection2',{ path: 'posts.collection3',{ path: 'posts.collection4',{ path: 'posts.collection5',])
  .sort({ createdAt: -1 })

  .exec((err,user) => {
    if (err) {
      return res
        .status(401)
        .send({ success: false,message: 'Server failed with respond' });
    }

.......

女巫给了我带有键/值的对象

"posts": {
        "collection1": [
            {
                "_id": "5febfccb613c268e5335451c","category": "musicians",}
        ],"collection2": [
            {
                "_id": "5febfccb613c268e5335845c","collection3": [],"collection4": [],"collection5": []
    },

我想要的是“帖子”:[] 所有集合中的所有文档都归入一个数组并进行排序。 谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...