I am working through a MEAN stack tutorial. It contains the following code as a route in index.js
. The name of my Mongo collection is brandcollection
.
/* GET Brand Complaints page. */
router.get('/brands', function(req, res) {
var db = req.db;
var collection = db.get('brandcollection');
collection.find({},{},function(e,docs){
res.render('brands', {
"brands" : docs
});
});
});
I would like to modify this code but I don't fully understand how the .find
method is being invoked. Specifically, I have the following questions:
What objects are being passed to
function(e, docs)
as its arguments?Is
function(e, docs)
part of the MongoDB syntax? I have looked at the docs on Mongo CRUD operations and couldn't find a reference to it. And it seems like the standard syntax for a Mongo.find
operation iscollection.find({},{}).someCursorLimit()
. I have not seen a reference to a third parameter in the.find
operation, so why is one allowed here?If
function(e, docs)
is not a MongoDB operation, is it part of the Monk API?It is clear from the tutorial that this block of code returns all of the documents in the collection and places them in an object as an attribute called "brands." However, what role specifically does
function(e, docs)
play in that process?
Any clarification would be much appreciated!