Unit 3 (Part B)
Unit 3 (Part B)
Unit 3 (Part B)
Mongo db
Managing Collections
• As a database admin, you may also find
yourself administering collections within a
database.
• Displaying a List of Collections in a Database
use test
show collections
Creating Collections
• To create a collection, you need to call
createCollection(name, [options]) on the
database handle. The name parameter is the
name of the new database.
• The optional options parameter is an object
that can have the properties
Options example
• capped A Boolean; when true, the collection is
a capped collection that does not grow bigger
than the maximum size specified by the size
attribute. Default: false
• autoIndexID A Boolean; when true, an _id field
is automatically created for each document
added to the collection and an index on that
field is implemented. This should be false for
capped collections. Default: true.
Creating a new collection in the MongoDB
console shell
• db.createCollection("newCollection")
Deleting Collections
• Removing old collections frees up disk space
and eliminates any overhead such as indexing
associated with the collection.
Finding Documents in a Collection
}
});
Adding the MongoDB Driver to Node.js
• Listing Databases
• MongoClient.connect("mongodb://localhost/admin",
function(err, db) {
• var adminDB = db.admin();
• adminDB.listDatabases(function(err, databases)
{ console.log("Before Add Database List: ");
console.log(databases);
• });
• });
Creating a Database