I need a way to view the bd
, collections and documents of MongoDb
. Since I usually communicate with mongo using mongoose
.
I would like to know a direct way from the console to access the features of one bd
that I have already created. With characteristics, I mean how a certain collection of objects is structured, the fields, validators, etc., that make it up, as well as its documents.
So far I know that if I write mongo
I get a shell
that allows me to interact with mongodb
, but I lack a bit of experience with this. Any help is appreciated.
MongoDB – basic commands
Now if first we are going to enter our linux or windows terminal and access the mongo console, once we enter from our terminal we are going to use the command:
show dbs;
this command shows us the databases we have in mongodb:
use [nombre de la base];
with this command we make use of a database, this command also creates a database for us and it will appear listed with
show dbs
;until we insert a document into the collection.
db.[coleccion].insert( [documento en formato JSON] ) ;
To insert and create a data collection in MongoDB we only have to use the statement
insert
and add the document (data) in JSON format, the collections are created automatically in mongodb once we insert an element or collection.show collections;
This command shows us the collections available in the database, remember to first select the database with the command
use
.db.[coleccion].find();
the command
find()
shows us the list of documents (“records”) of a collection, we can filter or send the find command to specify the results of our query.db.[coleccion].find().pretty();
If we want the results to look much better or give it a more visible output on the screen, we just have to add pretty() to the query that will make the result look pretty!
For more information about the JSON notation you can use this link http://www.w3schools.com/json/json_syntax.asp , you can find the mongodb documentation in this link to see in depth the commands shown here https://docs .mongodb.org/manual/
This link on basic Mongo shell commands (ie what you access when
mongo
you type ) may help:https://jarriagadeveloper.wordpress.com/2016/01/19/mongodb-comandos-basicos/