Understanding the Collection Object

The Collection object represents a collection in the MongoDB database. You use the Collection object to access items in the collection, add documents, query documents, and much more.

You can get a Collection object by using the collection() method on an instance of the Db object or by passing a Db object and collection name to the constructor. If the collection isn’t already created on the MongoDB server, you can create it by using the createCollection() method on the Db object. For example, all of the following work:

var collection = db.collection()var collection = new Collection(db, "myCollection")db.createCollection("newCollection", function(err, collection){ }

Table 13.7 lists ...

Get Node.js, MongoDB, and AngularJS Web Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.