In the last section we went ahead and installed MongoDB, I showed you how to log into the shell and create a database, as well as create a collection. Now what we'll do is create the database for our application, for our nodeauth
application. We'll insert some data and I'll also show you how to fetch that data from the shell.
So let's create a new database:
- To do that we can simply use
use
and then name it. I'm going to call thisnodeauth
:
use nodeauth
- You can see we switch to
nodeauth
and we want to create a collection called users. Let's saydb.createCollection
and I'll call thisusers
:
db.createCollection('users');
We'll run that and now if we say show collections
we have users
.
- Now to insert a user, we can simply use
db.users.insert
and then insert a document, which is basically just a JSON object. So we need our curly braces and the first thing we'll give it is aname
, I'll use my name. - The next thing we want is
email...