[英]mongodb : how to get documents that contains nested field
How can i get documents that contains nested field f5=12? 如何获取包含嵌套字段f5 = 12的文档?
db.products.insert( { f: "card", f1: {f2 : {f3 : 15 } } } )
db.products.insert({f:“ card”,f1:{f2:{f3:15}}})
db.products.insert( { f: "card", f1: {f2 : {f4 : {f5 : 12} } } } )
db.products.insert({f:“ card”,f1:{f2:{f4:{f5:12}}}})
db.products.insert( { f: "card", f1: {f2 : {f3 : {f5 : 43} } } } )
db.products.insert({f:“ card”,f1:{f2:{f3:{f5:43}}}})
db.products.insert( { f: "card", f1: {f2 : {f4 : 98 } } } )
db.products.insert({f:“ card”,f1:{f2:{f4:98}}})
I've tried smth like this: 我试过这样的东西:
db.products.find($where : "this.content.indexOf('f5 : 12') != -1")
db.products.find($ where:“ this.content.indexOf('f5:12')!= -1”)
db.products.find( {$elemMatch : {f5 : 12} })
db.products.find({$ elemMatch:{f5:12}})
But it doesn't work.. Does anyone has any ideas? 但这是行不通的。有人有任何想法吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.