Mongo查询语句数组内属性语句

查询history表结构为:

{
    "_id" : ObjectId("5dbba2cfb834740008dd62e7"),
    "callStatus" : {
        "callId" : "5dafa7aa-177e-45ff-9193-9ac615716d6a",
        "seatEmotion" : "正常",
        "speechRate" : "216字/分"
    },
    "flowQualityInspection" : {
        "callId" : "5dafa7aa-177e-45ff-9193-9ac615716d6a",
        "flowId" : "ef1a87ab503545558b8108ab88d59442",
        "navigations" : []
    },
    "viewUserPortraits" : [],
    "chatMessages" : [ 
        {
            "_id" : ObjectId("5dbba2f3b834740008dd62e8"),
            "callId" : "5dafa7aa-177e-45ff-9193-9ac615716d6a",
            "agentId" : "836",
            "text" : "很高兴服务到您这样就是嗯",
            "role" : 0,
            "time" : "00:00:30",
            "index" : 1474
        }, 
......

 

想查询某一数组元素中特定属性值的mongo语句:

db.getCollection('history').find({chatMessages:{$elemMatch : {"text":"很高兴服务到您这样就是嗯"}}})

如果对象有一个元素是数组,那么$elemMatch可以匹配内数组内的元素

posted @ 2019-11-25 20:40  Noctis33  阅读(558)  评论(0编辑  收藏  举报