样例数据:
{
"cNo" : "11", "Details" : [ { "dDate" : ISODate("2017-04-01T00:00:00.000+0800"), "bNo" : "No00000000497" }, { "dDate" : ISODate("2017-05-01T00:00:00.000+0800"), "bNo" : "No00000000497" }, { "dDate" : ISODate("2017-06-01T00:00:00.000+0800"), "bNo" : "No00000000497" } ] } { "cNo" : "12", "Details" : [ { "dDate" : ISODate("2017-04-01T00:00:00.000+0800"), "bNo" : "No00000000497" }, { "dDate" : ISODate("2017-05-01T00:00:00.000+0800"), "bNo" : "No00000000497" }, { "dDate" : ISODate("2017-06-01T00:00:00.000+0800"), "bNo" : "No00000000500" } ] } { "cNo" : "13", "Details" : [ { "dDate" : ISODate("2017-04-01T00:00:00.000+0800"), "bNo" : "No00000000497" }, { "dDate" : ISODate("2017-05-01T00:00:00.000+0800"), "bNo" : "No00000000497" }, { "dDate" : ISODate("2017-06-01T00:00:00.000+0800"), "bNo" : "No00000000497" } ] }查询条件:dDate等于2017-06-01,且bNo等于No00000000497的数据
正确查询语句:{Details:{ $elemMatch:{ "bNo":"No00000000497","dDate": ISODate("2017-10-01T00:00:00.000+0800") } }}
查询结果:11、13
(非完全匹配/错误)查询语句:{"Details.bNo":"No00000000497","Details.dDate":ISODate("2017-10-01T00:00:00.000+0800")}
查询结果:11、12、13