Now that we have our database created and we have a user now we can start creating collections.
Now that we have our collection built out we can start adding documents into our database. I'm going to open up sublime text and let's start writing out the script that is going to insert a book into our book collection.
In the last guide, we walked through how you can insert documents into a Mongo collection and that's great but that only allowed us to insert one at a time.
So far in this course, we have focused primarily on just adding documents but that's only one part of how Mongo is used. We also need to be able to retrieve those. What we can do is we have a number of different find methods in Mongo that make it very straightforward to query documents.
As helpful as it is to be able to perform a find query on an entire collection more often than not you're going to be performing some type of query based off of a value in that collection.
In the past few guides as we've been going through some of the various querying functions that are available in Mongo you may have noticed something that might be kind of strange if you remember back where we run some command like db.books.find() do you notice how all of the attributes are brought back.
Now that you're familiar with how projections work in Mongo what we can do is we can actually dive down even further to be able to be more explicit with what gets returned back for nested collections.
So far we've gone through a number of ways to query documents in Mongo. We've also talked about inserting either single or multiple documents.
In production applications that utilize Mongo's database a very common pattern that you'll see is that your documents start to get pretty big and you start to have a number of nested collections. It's one of the top reasons why you actually use a document based system like Mongo because you have the flexibility and then you also have the ability to nest as many items as you want.
This is going to be a quick guide on how to drill down and become more specific with our search queries. Specifically, in being more specific with how many elements get returned.
This is going to be a very important guide and that's because this is going to be one of the guides we're get into some very similar code that you're going to see in production applications that use Mongo.
In this guide, we're going to walk through how we can check to see if a field exists or if it doesn't inside of Mongo.
devCamp does not support ancient browsers.
Install a modern version for best experience.