如何在mongodb中获取嵌入式文档? [英] How to get embedded document in mongodb?

查看:97
本文介绍了如何在mongodb中获取嵌入式文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用mongodb在表中获取嵌入式文档,但是它不起作用.

I tried to get embedded documents in the table using mongodb but its not working.

dev表

[{
"id":1,
"data":[{"id":1,"name":true},{"id":2,"name":true},{"id":3,"name":false},{"id":1,"name":true}]
}]

查询

db.dev,find({data.name:true})

例外的输出

[{
"id":1,
"data":[{"id":1,"name":true},{"id":2,"name":true}]
}]

我得到了输出

[{
"id":1,
"data":[{"id":1,"name":true},{"id":2,"name":true},{"id":3,"name":"false"},{"id":1,"name":true}]
}]

如何编写查询以匹配期望的输出.可以提供示例代码

How to write the query to match the expected output. can give sample code

推荐答案

尝试此解决方案

let whereClause = { "data.name":true };
    await db.dev.find(whereClause);

这篇关于如何在mongodb中获取嵌入式文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆