Files
notes/tiddlywiki/MongoDB - scratchpad.txt
2026-03-12 22:01:38 +01:00

36 lines
975 B
Plaintext
Executable File

> use db01
-- create database db01 if it does not exists
> db
-- show current database
> show dbs
-- list databases
-- db01 is not listed until it does not contain at least a document
> db.movies.insertOne({"title" : "Stand by Me"})
-- create index
> db.users.createIndex({"age" : 1, "username" : 1});
-- list indexes of a collection
> db.users.getIndexes();
-- show explain plan
> db.users.find({"username": "user999999", "age":"19"}).explain("executionStats");
# https://www.mysoftkey.com/mongodb/how-to-enable-authentication-and-authorization-using-scram-sha-1-in-mongodb/
-- Connection String URI Format
https://docs.mongodb.com/manual/reference/connection-string/index.html#connections-dns-seedlist
-- shutdown MongoDB
> use admin
> db.shutdownServer();
-- count(*) of a collection
db.elements.countDocuments({})
-- truncte a collection
db.elements.remove({})
-- display the last 5 inserted documents of a collection
db.elements.find().sort({_id:-1}).limit(5);