简体   繁体   English

如何在不打印特定兄弟姐妹的情况下引用 mongodb 中的兄弟姐妹 ID

[英]How to reference sibling id in mongodb without printing that particular sibling

enter image description here I'm trying to use mongosh to retrieve the details of the other siblings, ie Child2 and Child3 by referencing the child1 document. enter image description here我正在尝试使用 mongosh 通过引用 child1 文档来检索其他兄弟姐妹的详细信息,即 Child2 和 Child3。 What mongosh condition should I use to get this and not the child1 and father document?我应该使用什么 mongosh 条件来获取这个而不是 child1 和 father 文档?

I tried the aggregate method and the find method, I tried to apply the logic of using the parent_id, which is common among the other siblings, but it prints the child1 id as well.我尝试了聚合方法和查找方法,我尝试应用使用 parent_id 的逻辑,这在其他兄弟姐妹中很常见,但它也会打印 child1 id。 Help!帮助!

I figured it out after some trial and error and I used the $ne function. So according to the image, the answer should be:经过反复试验,我弄明白了,我使用了$ne function。所以根据图像,答案应该是:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM