Connect to mongodb
root@mongo:/home/mongo# mongosh "mongodb://admin:adminpassword@localhost:27017"
Create the database, just command use
test> use analytics
switched to db analytics
Create the collection
analytics> db.createCollection("traffic");
Insert one record on the collection
analytics> db.traffic.insertOne({ message: "Analytics database initialized", timestamp: new Date() })
Use admin database
analytics> use admin
switched to db admin
Create a user on the database admin
admin> db.createUser({ user: "userName", pwd: "passwdthatyouwant", roles: [{ role: "readWrite", db: "DBthatyouwant" }] });
{ ok: 1 }
No hay comentarios:
Publicar un comentario