在SpringBoot App中使用地图数组查询Mongo文档

时间:2018-10-16 13:42:27

标签: mongodb spring-boot mongodb-query spring-mongo

我在MongoDB上有一个SpringBoot应用程序。该数据库具有以下结构的文档。

我正在尝试在Repository类(扩展MongoRepository)中编写一个方法,该方法将允许我在以下位置获取文档:

  1. GATE_1,GATE_2和GATE_3是真实的。
  2. GATE_1,GATE_2,GATE_3是真实的,而FEATURE_1是真实的。

最终,存储库类中的方法由Controller中的方法调用-本质上是一个REST API,可为这些API提供门名称,功能名称和期望值。我环顾四周,但没有找到类似的问题。如果我错过了一个已经提出的问题,请转介我到该问题。

{
    "_id" : JUUID("80e5ab1b-cc46-48c2-b6f1-ef73db6b07d0"),
    "_class" : "com.mycompany.myservice.model.mymodel",
    "createDate" : ISODate("2018-10-15T18:54:52.000Z"),
    "field1Version" : "9850691",
    "field2Version" : "8950691",
    "field3Version" : "9967662",
    "field4Version" : "d047fb9",
    "type" : "META",
    "features" : [ 
        {
            "featureName" : "FEATURE_1",
            "featureValue" : "true",
            "createDate" : ISODate("2018-10-15T05:59:21.000Z")
        }
    ],
    "gates" : [ 
        {
            "gateName" : "GATE_1",
            "gateValue" : "true",
            "createDate" : ISODate("2018-10-15T05:59:21.000Z")
        }, 
        {
            "gateName" : "GATE_2",
            "gateValue" : "false",
            "createDate" : ISODate("2018-10-18T08:59:21.000Z")
        }, 
        {
            "gateName" : "GATE_3",
            "gateValue" : "true",
            "createDate" : ISODate("2019-02-11T02:46:01.000Z")
        }
    ]
},
{
    "_id" : JUUID("80e5ab1b-cc46-48c2-b6f1-ef73db6b07d0"),
    "_class" : "com.mycompany.myservice.model.mymodel",
    "createDate" : ISODate("2018-10-15T18:54:52.000Z"),
    "field1Version" : "6789691",
    "field2Version" : "5980691",
    "field3Version" : "9997662",
    "field4Version" : "d047fb9",
    "type" : "META",
    "features" : [ 
        {
            "featureName" : "FEATURE_1",
            "featureValue" : "true",
            "createDate" : ISODate("2018-10-15T05:59:21.000Z")
        }
    ],
    "gates" : [ 
        {
            "gateName" : "GATE_1",
            "gateValue" : "true",
            "createDate" : ISODate("2018-10-15T05:59:21.000Z")
        }, 
        {
            "gateName" : "GATE_2",
            "gateValue" : "true",
            "createDate" : ISODate("2018-10-18T08:59:21.000Z")
        }, 
        {
            "gateName" : "GATE_3",
            "gateValue" : "true",
            "createDate" : ISODate("2019-02-11T02:46:01.000Z")
        }
    ]
}

0 个答案:

没有答案