LoginSignup
13
16

More than 5 years have passed since last update.

MongoDB 最低限知っておくべきコマンド

Last updated at Posted at 2015-07-14

データベース選択

use database

データベース一覧表示

show dbs

コレクション一覧表示

show collections

データベース削除

use database
db.dropDatabase()

データベースコピー

db.copyDatabase('fromDatabase', 'toDatabase')

コレクション作成

db.createCollection('collection')

コレクション削除

db.collection.drop()

コレクション名変更

db.oldCollection.renameCollection('newCollection')

コレクション複製

db.oldCollection.find().forEach(function (x) {db.newCollection.save(x)})

インデックス作成

OLD!!
db.collection.ensureIndex({name: 1})
New!!
db.collection.createIndex({name: 1})

インデックス削除

すべてのインデックス削除
db.collection.dropIndexes()

個別にインデックス削除

db.collection.dropIndex({name: 1})

全件表示

db.collection.find().forEach(printjson)

indexとかもろもろ確認

db.collection.stats()

13
16
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
13
16