6
6

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

MongoDB周りのメモ

Posted at

接続

mongo
mongo ホスト名/DB名

DB一覧

mongo
show dbs;

コレクション一覧

mongo
show collections;

条件付きで取得

  • where AAA = BBB
mongo
db.access_log.find({code: 200});
  • where AAA = BBB and CCC = DDD
mongo
db.access_log.find({code: 200, method: "GET"});
  • where AAA in (BBB, CCC, …)
mongo
db.access_log.find({code: {$in: [200, 300, 400]}});

な感じ

最新10件取得

mongo
db.コレクション名.find().sort({_id: -1}).limit(10);

アクセスログ的な奴だったら時間で絞ると早い。

ISODateで今日の日付を入れて

mongo
db.コレクション名.find({
  time: {$gte: ISODate("2012-06-28T00:00:00+09:00")}
}).sort({_id: -1}).limit(10);
6
6
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
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?