CRUD using the shell
The mongo shell is equivalent to the administration console used by relational databases. Connecting to the mongo shell is as easy as typing the following code:
$ mongosh
Type this on the command line for standalone servers or replica sets. Inside the shell, you can view available databases simply by typing the following code:
$ db
Then, you can connect to a database by typing the following code:
> use <database_name>
The mongo shell can be used to query and update data in our databases. Inserting this document into the books
collection can be done like so:
> db.books.insertOne({title: 'mastering mongoDB', isbn: '101'}) { acknowledged: true, insertedIds: { '0': ObjectId("627f8178d95a9c017a390229") }
We can then find documents from a collection named books
by typing the following code:
> db.books.find() { ...