Now, for the "removeDocument," I'm going to say, "collection deleteOne."
So, I'll try to find the first document that
matches what we have specified and then delete it.
And then this will take, again,
a callback function as a second parameter,
and inside this callback function,
the first thing that I check is to make sure that the error is not null.
And then after that, we will say,
"console log removed the document comma document."
We used the comma here because this is a JavaScript object so,
if you specify console log like this,
the document will be printed out and then we'll pass
that result back through the callback function.
And then finally, for the update we'll coll.updateOne.
This is a method the MongoDB driver supports.
So, I'll say, "update.One document,
" and the second parameter is where we
will pass in the fields that need to be updated.
And the way it is done,
we'll say, "dollar set colon update."
So, this will take the update information that
I'm sending in and then pass it into the update.One.
The first one is the document that needs to be updated.
The second one is which fields of the document needs to be updated here.
And the third parameter is null,
and that last parameter is a callback function,
which obviously will give us the result of the operation.
So, first thing I'm going to check to make sure that the error is not null.
Then, I'll do a "console log updated the document with."
Now again, the console logs are purely for us to
ensure that the code is doing what it is doing.
It doesn't help in any way.
This is just for our own information.
In a production server,
you would not be having this console logs, maybe.
You can disable them. So, that's it.
So four methods being supported in this particular file-based node module insert,
find, remove and update.
So, now that we have implemented this file-based node module,
let's go to the index.js file,
and then to make use of that file-based node module,
I need to require this here.
So, I'll say, "const dboper require."
Since this is a file-based node module you get the full path to the node module,
and which in this case happens to be./operations
because it is in the same folder as my index.js file.
Now, once we have done this,
then right here, this function,
this code that we were doing to access the database now insert,
we will be using the dboper that we have just implemented to access that database.
So, we'll say, "dboper insert document,
" and this "insert document" takes the db as the first parameter.
The db here, is this db that came in when we call MongoClient connect.
So that db will be passed in, so that way,
my operations node module knows where to access the database.
Then the second parameter is the,
so if you look at the "insert document" you will see
that the second parameter is the document to be inserted.
So, I will say, "name. "