C# mongodb中内嵌文档数组条件查询

样例数据:

    "_id" : "1064621564857", 
    "cNo" : "1064621564857", 
    "exPCodes" : [
        {
            "pType" : NumberInt(1), 
            "cDate" : ISODate("2017-07-27T10:30:11.783+0800")
        }
    ]
}
    "_id" : "1064621565572", 
    "cNo" : "1064621565572", 
    "exPCodes" : [
        {
            "pType" : NumberLong(3), 
            "cDate" : ISODate("2017-08-25T12:06:08.278+0800")
        }
    ]
}
    "_id" : "1064621565721", 
    "cNo" : "1064621565721", 
    "exPCodes" : [
        {
            "pType" : NumberLong(2), 
            "cDate" : ISODate("2017-07-14T14:44:00.522+0800")
        }
    ]
}

查询 exPCodes的cDate是2017-07月份的,且pType等于1的:

 { "exPCodes": { $elemMatch: { cDate: { $gte: ISODate("2017-07-01T00:00:00.000+0800"), $lte: ISODate("2017-07-31T00:00:00.000+0800") },pType:1} } }

原文地址:https://www.cnblogs.com/94cool/p/7381383.html