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 3 years have passed since last update.

MongoDBコマンドの最低限の自分用メモ

Posted at

はじめに

Node.js × expressでAPIを作る際にDatabaseでmongoDBを採用しました。
そのときに、CLIからの使い方で少し躓いたので必要最低限のメモを残す。

CLIに入る

mongo

DB一覧確認

show dbs

DB選択

use db_name

※mongo時に省略可能

mongo db_name

Table一覧確認

show collections

※tablesでもいける

show tables

全件取得

db.table_name.find();

一件取得

db.table_name.findOne();

個数

db.table_name.count();

sort

db.table_name.find().sort({ createdAt: -1 }); 

-1は降順1は昇順

登録

db.table_name.insert({ title: "mongo" });

更新

db.table_name.update({ title: "mongo2" });

削除

 db.table_name.remove({title: "mongo2" });
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?