Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

1 Answer
Samual Sam

The group is a type of method in MongoDB. It shouldn’t be created as a collection name. Even if you created it, you can easily remove it using getCollection('group').drop();). Let us first create a collection with documents −

> db.createCollection('group');
{ "ok" : 1 }
> db.getCollection('group').insertOne({"StudentName":"Chris"});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5cb80fe9623186894665ae3c")
}
> db.getCollection('group').insertOne({"StudentName":"Robert"});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5cb80fef623186894665ae3d")
}

Following is the query to display all documents from the collection with the help of find() method −

> db.getCollection('group').find().pretty();

This will produce the following output −

{ "_id" : ObjectId("5cb80fe9623186894665ae3c"), "StudentName" : "Chris" }
{ "_id" : ObjectId("5cb80fef623186894665ae3d"), "StudentName" : "Robert" }

Following is the query to remove the collection named ‘group’ −

> db.getCollection('group').drop();

This will produce the following output −

True

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.