Skip to content

Instantly share code, notes, and snippets.

@tokunami
Last active August 29, 2015 14:06
Show Gist options
  • Save tokunami/068874187eaf169052e6 to your computer and use it in GitHub Desktop.
Save tokunami/068874187eaf169052e6 to your computer and use it in GitHub Desktop.
mongoDB コマンドいろいろ
  • 起動
mongod --dbpath <path>
  • シェルの起動
$ cd <path> //dbpath
$ mongo
  • シェルコマンド

    事前準備

> show dbs  //存在しているデータベースを確認して(省略可)
admin  (empty)
hoge     0.078GB
local  0.078GB
> use hoge  //使用するデータベースを選択する
switched to db ap

コレクション操作

> show collections  //存在しているコレクションを確認して(省略可)
system.indexes
fugas
> db.fugas.count()  //fugasコレクション内のデータ数をカウント
> db.fugas.find()  //fugasコレクション内のデータを表示
> db.fugas.drop()  //fugasコレクション内のデータを消去

()内に条件を入れる。オブジェクト形式。

@stoshiya
Copy link

stoshiya commented Oct 6, 2014

コレクション内のデータを消去するのはdb.collection.remove()で,db.collection.drop()はコレクションそのものを消去します.

http://docs.mongodb.org/manual/reference/method/db.collection.remove/
http://docs.mongodb.org/manual/reference/method/db.collection.drop/

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