问题
I tried to get embedded documents in the table using mongodb but its not working.
dev table
[{
"id":1,
"data":[{"id":1,"name":true},{"id":2,"name":true},{"id":3,"name":false},{"id":1,"name":true}]
}]
Query
db.dev,find({data.name:true})
Excepted output
[{
"id":1,
"data":[{"id":1,"name":true},{"id":2,"name":true}]
}]
I got Output
[{
"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
回答1:
Try out this solution
let whereClause = { "data.name":true };
await db.dev.find(whereClause);
来源:https://stackoverflow.com/questions/58815958/how-to-get-embedded-document-in-mongodb