【问题标题】:MongoDb search for all documents where some filed inside array of array is equals to some valueMongoDb搜索所有文档,其中一些在数组数组中的文件等于某个值
【发布时间】:2021-11-07 08:29:27
【问题描述】:

我需要通过 azure 门户在 MongoDb 集合上执行过滤,我需要找到字段 SystemServerId 等于 125104 的所有文档

这是文档的基本版本:

{
    "_id" : "613a7c1ce007cf00167cd07a",
    "UserId" : 334645,
    "Events" : [
        {
            "UserManagerId" : 334645,
            "Method" : "MethodXXX",
            "EventLogs" : [
                {
                    "Classe" : "ClassXXX"
                }
            ],
            "SystemTracer" : {
                "UsersServers" : [
                    {
                        "SystemServerId" : 125104
                    }
                ]
            }
        }
    ]
}

我在 MongoDb 网站上阅读了一些关于聚合的文档,但是,我没有管理如何制作这个过滤器,我尝试了什么:

{ Events: { "SystemTracer.UsersServers": { SystemServerId:125104 } } }

{ "Events": { "SystemTracer": { "UsersServers": { SystemServerId:125104 } } } }

这个过滤器有很多变体...... 那么,我可以过滤收集的文档吗?

【问题讨论】:

标签: mongodb


【解决方案1】:

你可以使用$elemMatch

db.collection.find({Events:{$elemMatch:{"SystemTracer.UsersServers":{$elemMatch:{SystemServerId:125104}}}}})

【讨论】:

    猜你喜欢
    • 2017-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-26
    • 2013-03-28
    • 2013-12-18
    • 1970-01-01
    相关资源
    最近更新 更多