MongoDB查询hashmap对象

时间:2018-04-27 13:07:52

标签: mongodb hashmap mongodb-query

我在&匹配'中有以下MondoDB文档。由Spring的MongoRepository创建的集合:

[
  {
    "_id" : ObjectId("123"),
    "scores" : {
      "11111" : 2,
      "22222" : 0
    },
    "playerOne" : {
      "$ref" : "player",
      "$id" : ObjectId("11111")
    },
    "playerTwo" : {
      "$ref" : "player",
      "$id" : ObjectId("22222")
    }
  },
  {
    "_id" : ObjectId("456"),
    "scores" : {
      "11111" : 3,
      "33333" : 1
    },
    "playerOne" : {
      "$ref" : "player",
      "$id" : ObjectId("11111")
    },
    "playerTwo" : {
      "$ref" : "player",
      "$id" : ObjectId("33333")
    }
  },
  {
    "_id" : ObjectId("789"),
    "scores" : {
      "44444" : 4,
      "11111" : 2
    },
    "playerOne" : {
      "$ref" : "player",
      "$id" : ObjectId("44444")
    },
    "playerTwo" : {
      "$ref" : "player",
      "$id" : ObjectId("11111")
    }
  }
]

文档包含两个玩家之间的匹配结果。在得分属性中存储了玩家的得分,其中是玩家ID,而是玩家得分。

我想通过玩家 id (例如 id:11111 )获得所有匹配,此玩家获胜者,所以他的得分大于对手。

你有什么想法为此写一个查询?我想避免重新设计文档,但如果它是编写正确查询的唯一方法,请继续。

0 个答案:

没有答案