在MongoDB中搜索子元素数组值

在MongoDB中搜索子元素数组值,mongodb,Mongodb,我的JSON格式有点奇怪,因为它是从XML转换而来的,但基本结构如下: { "World": { "Continents": { "Continent": [ "Asia", "Europe", "Africa" ] } } } 我试图返回大陆=亚洲的案例。我尝试了很多方法,但我怀疑这是一种有效的方法: db.testing.find( { "World.Continents": { $elemMa

我的JSON格式有点奇怪,因为它是从XML转换而来的,但基本结构如下:

{
  "World": {
    "Continents": {
      "Continent": [
        "Asia",
        "Europe",
        "Africa"
      ]
    }
  }
}
我试图返回大陆=亚洲的案例。我尝试了很多方法,但我怀疑这是一种有效的方法:

db.testing.find( { "World.Continents": { $elemMatch: { "Continent": "Asia" }}})

我还根据World.Continents.Continental上的一个查找结果进行了各种查询,但由于各种语法原因,它向我抛出了无数错误。

您可以使用此查询:

db.testing.find( { "World.Continents.Continent":  "Africa" } )

哇!是 啊我不知道这是不是太直截了当了,以至于我懒得去尝试,或者我是不是太胖了。谢谢你的帮助。