0
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?

mongoshで使うコマンド一覧

Posted at

mongoshで使うコマンド一覧について記載

#mongosh起動
$mongosh --host <host> --port <port> -u <user> -p <pwd>


#dbを全て表示
$show dbs

#使うDBを選択
$use <database_name>

#コレクションを全て表示
$show collections

#データを作成
$db.coll.insertOne({name: "name"})

#データを作成(複数)
$db.coll.insert([{name: "name1"}, {name:"name2"}]) 

#documentのデータを一つ表示
$db.coll.findOne() 

#documentのデータを全て表示
$db.coll.find()  

#テキスト検索
$db.coll.find({$text: {$search: "name1"}})

#データの更新
$db.coll.update({"_id": 1}, {$set: {name: "Name2"}}) 

#indexを取得
$db.coll.getIndexes() 

#indexのkeyを取得
$db.coll.getIndexKeys()

#indexの作成
$db.coll.createIndex({"name": 1})   

#indexの削除
$db.coll.dropIndex("name_1")

#データの削除
$db.coll.remove({name: "name1"})

#コレクションの削除
$db.coll.drop() 

#dbを全て削除
$db.dropDataBase() 

#jsファイルの実行
$load(xxx.js)


以上

0
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
0
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?