【问题标题】:How to reference sibling id in mongodb without printing that particular sibling如何在不打印特定兄弟的情况下在 mongodb 中引用兄弟 ID
【发布时间】:2022-11-21 16:46:03
【问题描述】:

enter image description here 我正在尝试使用 mongosh 通过引用 child1 文档来检索其他兄弟姐妹的详细信息,即 Child2 和 Child3。 我应该使用什么 mongosh 条件来获取这个而不是 child1 和 father 文档?

我尝试了聚合方法和查找方法,我尝试应用使用 parent_id 的逻辑,这在其他兄弟姐妹中很常见,但它也会打印 child1 id。帮助!

【问题讨论】:

    标签: mongodb mongoose mongodb-query aggregation-framework mongo-shell


    【解决方案1】:

    经过反复试验,我弄明白了,我使用了 $ne 函数。所以根据图像,答案应该是:

    db.family.find({parent_id: "1", _id:{$ne:2}})

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多