March 2019
Intermediate to advanced
394 pages
11h 4m
English
Administering the database using built-in commands is helpful, but it's not the main reason for using the shell. The true power of the mongo shell comes from the fact that it is a JavaScript shell.
We can declare and assign variables in the shell as follows:
> var title = 'MongoDB in a nutshell'> titleMongoDB in a nutshell> db.books.insert({title: title, isbn: 102})WriteResult({ "nInserted" : 1 })> db.books.find(){ "_id" : ObjectId("59203874141daf984112d080"), "title" : "MongoDB in a nutshell", "isbn" : 102 }
In the previous example, we declared a new title variable as MongoDB in a nutshell and used the variable to insert a new document into our books collection, as shown in the following code.
As it's a JavaScript ...
Read now
Unlock full access