2016-05-25 7 views
0

例えば、私はこのような構造を持っている: "私は「経度」を含む名前のすべての都市、私はこのexempleで取得できる方法を知って好きですが、キーを指定せずに考えMongoDB、キーを指定せずにMongoDBの子オブジェクトを照会するには?

{ 
    name:{ 
     "en":"london", 
     "fr":"londres", 
     "sq":"londra" 
    }, 
    ... 
}, 
{ 
    name:{ 
     "de":"barcelona", 
     "sv":"barcelone" 
    }, 
    ... 
} 
... 

(「ド」またはfr ")?

だから、ないこの:

db.cities.find({$or:{"name.en":/lon/,"name.fr":/lon/, ...}}) 

しかし、のようなもの:

db.collection.createIndex:これは、すべてのフィールドを含めるtext indexを作成することができますを取得する

db.cities.find({"name":/lon/}}) 
-> find in the children of "name, don't care about the key 

答えて

0

({"$ **": "text"、 })

その後、クエリで$searchを使用 - 単語を茎more here

db.cities.find({ $text: { 
      $search: "lon", 
      $caseSensitive: true, 
     $diacriticSensitive: true 
    } }) 
+0

おかげではなく、テキストインデックスは唯一の完全に動作します... –

関連する問題