2016-12-06 56 views
1

我有這個在我的分貝:如何迭代和過濾rethinkdb數據庫提交?

{ 
    "id": "d40110a1-c0ca-47e0-95ca-086e905dd53c", 
    "somefiled": [ 
     { 
      "city_name": "Aadorf", 
      "de": "Aadorf", 
      "en": "Aadorf", 
      "fr": "Aadorf", 
      "it": "Aadorf", 
      "kanton_de": "Thurgau", 
      "kanton_en": "Thurgovie", 
      "kanton_fr": "Thurgau", 
      "kanton_it": "Turgovia" 
     }, 
     { 
      "city_name": "Aarau", 
      "de": "Aarau", 
      "en": "Aarau", 
      "fr": "Aarau", 
      "it": "Aarau", 
      "kanton_de": "Aargau", 
      "kanton_en": "Argovie", 
      "kanton_fr": "Aargau", 
      "kanton_it": "Argovia" 
     }//many more records here] 
} 

我怎麼能提取somefiled所有的數組元素,其中值爲kanton_en是Argovie?

事情是這樣的:

r.db("test").table("table").getField("somefiled").filter(function(row){ 

    return row("kanton_en").eq("Argovie") 
}) 

但是,這當然是返回什麼。

回答

1

解決了:

r.db("test").table("test").getField("somefiled").concatMap(function(row){ 

    return row.filter(function(b){ 

    return b("kanton_en").eq("Argovie") 
    }) 
})