Now that you have inserted some documents into your MongoDB collections, I want to take a moment to talk about the _id
property in the context of MongoDB because it's a little different than the IDs that you're probably used to if you've used other database systems, like Postgres or MySQL.
To kick off our discussion of the _id
property, let's go ahead and rerun the mongodb-connect
file. This is going to insert a new document into the Users collection, like we've defined in the db.collection
line. I'm going to go ahead and do that by running the file through the node. It's in the playground
folder, and the file itself is called mongodb-connect.js
:
node playground/mongodb-connect.js
I'm going to run the command, and we're going to print out the document that got inserted:
As we've seen in the past, we get our three attributes as well as the one added by Mongo.
The first thing you'll notice about this is that it is not an auto incrementing integer...