Skip to content

Instantly share code, notes, and snippets.

@kenjikaneko
Created November 15, 2012 06:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenjikaneko/4076910 to your computer and use it in GitHub Desktop.
Save kenjikaneko/4076910 to your computer and use it in GitHub Desktop.
list up the mongodb commands usually using

##mongodb よく使うシェルコマンド集

  • データ検索
    → db.collection.find({ field:value })
  • nestデータの検索
    → db.collection.find({ "field1.field2":value })
  • 範囲検索
    → db.collection.find({ field: { $gt:value1, $lt:value2 }})
  • 不等号検索
    → db.collection.find({ field: { $ne:value }})
  • or検索 ※1 → db.collection.find({ $or: [{ field1:value1 }, {field2:value2}]})
  • データ削除
    → db.collection.remove({ field:value })
    *新規collection 作成
    → db.createCollection( collection, { capped:true, size:10000000 })
  • データupdate
    → db.collection.update({ field1:value }, { $set:{ field2:value }}, true)
     第一引数: 検索クエリ, 第二引数: insertしたいデータ, 第三引数: upsertフラグ ※2 ※3

######備考 ※1 条件オペレータを使用する際のfield指定は、ネストを扱うことができない 高度なクエリー http://www.mongodb.org/pages/viewpage.action?pageId=6029357#%E9%AB%98%E5%BA%A6%E3%81%AA%E3%82%AF%E3%82%A8%E3%83%AA%E3%83%BC-%24or  $or
※2 capped されているcollction には変更を加えることができない
Capped Collections
http://www.mongodb.org/display/DOCS/Capped+Collections
通常のコレクションでも前もってスペースを確保
※3 $set以外の modifier オペレーションは下記
http://www.mongodb.org/pages/viewpage.action?pageId=7209549#%E3%82%A2%E3%83%83%E3%83%97%E3%83%87%E3%83%BC%E3%83%88-%24set
modifier オペレーション

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment