4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

mongodbでfindで深い階層のフィールドを指定して取得する

Last updated at Posted at 2017-04-24

深い階層のフィールドを指定する場合

次のような構造のデータがあるとする。

hogehoge.json
{
"id":"1"
"name":"xxx"
"address":{
    "pref":"abc"
    "city":"def"
    "after":"ghi"
},
{
"id":"2"
"name":"yyy"
"address":{
    "pref":"jkl"
    "city":"mno"
    "after":"pqr"
}

addressの下のafterで検索したい場合は次ようになる。

db.hogehoge.find({"address.after": "pqr"});

参考URL

http://nisihunabasi.mods.jp/blog/?p=683
https://ja.wikipedia.org/wiki/MongoDB#.E3.83.8D.E3.82.B9.E3.83.88.E3.81.95.E3.82.8C.E3.81.9F.E3.83.95.E3.82.A3.E3.83.BC.E3.83.AB.E3.83.89.E3.81.AE.E3.82.AF.E3.82.A8.E3.83.AA

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?