1
0

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】リストの中身があるドキュメントだけ抽出する

Posted at

前提

以下のようなcollectionから"numbers"の中身があるドキュメントだけ抽出したい.

{
   "numbers": [1,2,3,4]
},
{
   "numbers": [1,2]
},
{
   "numbers": []
}

解決策

これが一番簡単だと思う.

> db.collection.find({"numbers.1": {$exists: true}})

カウントするならこれ.

> db.collection.count({"numbers.1": {$exists: true}})
1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?