0

我有一个架构:

{
            thread_id: String,
            users:[
                {
                    id: String, 
                    name: String, 
                    status: {type: String, enum:["ACTIVE", "LEAVE"]},
                }
            ],
            events:[
                {
                    event_name: {type: String, enum:["Joined", "Left"]},
                    when: Date, 
                    user_id: String
                }
            ],
            messages:[
                {
                    user_id: String,
                    message_id: String,
                    content:
                    {
                        type: {
                            type: String,
                            enum: ["TEXT", "IMAGE", "AUDIO"]
                        },
                        data: String,
                    },
                    sender_name: String,
                    receiver_name: String,
                    sender: String,
                    receiver: String,
                    seen: {
                        type: Boolean,
                        default: false
                    },
        
                    create_date: {
                        type: Date,
                        default: Date.now()
                    }
        
                }
            ]
        },

我想通过这样的用户 id 数组查询 ["447573454343", "2485​​73454353"],如何得到上面有两个用户的确切结果?非常感谢!!!............................................ ..................................................... .....................................

4

1 回答 1

0

您可以使用 $all 运算符:

db.coll.find(
    {
        "users.id": { $all: ['447573454343', '248573454353'] }
    }
)
于 2020-12-17T18:47:51.677 回答