Database Reference
In-Depth Information
There are three parts to the insert( ) function:
Database . We need to identify which database we would like to add documents
to. When we first start the MongoDB client, there is a variable called db that is as-
signed to represent the database for the current connection. Variables are pointers
to the actual data they are assigned. Think of db as the pointer to your database. By
default, db points to the test database. To see this yourself, type db at the command
prompt and hit <Enter>.
Collection . We need to identify the collection within this database we would like
to add documents to.
Documents . We need to list the one or more documents that will be added to the
collection. We can add one document, or we can add many documents using an
array.
For example, to add a new book document into the book collection, we can execute this
statement:
Search WWH ::




Custom Search