How to drop a numeric collection from MongoDB?

In MongoDB, numeric collection names cannot be accessed using standard dot notation. To drop a numeric collection, use the getCollection() method followed by drop().

Syntax

db.getCollection("numericCollectionName").drop();

Create Sample Data

First, create a numeric collection ?

db.createCollection("2536464");
{ "ok" : 1 }

Now insert some documents in the collection ?

db.getCollection("2536464").insertMany([
    {"Record": 1},
    {"Record": 2},
    {"Record": 3}
]);
{
    "acknowledged" : true,
    "insertedIds" : [
        ObjectId("5ca254a46304881c5ce84b8e"),
        ObjectId("5ca254a76304881c5ce84b8f"),
        ObjectId("5ca254a96304881c5ce84b90")
    ]
}

Verify Collection Data

Display all documents to confirm the data ?

db.getCollection("2536464").find();
{ "_id" : ObjectId("5ca254a46304881c5ce84b8e"), "Record" : 1 }
{ "_id" : ObjectId("5ca254a76304881c5ce84b8f"), "Record" : 2 }
{ "_id" : ObjectId("5ca254a96304881c5ce84b90"), "Record" : 3 }

Drop the Numeric Collection

Remove the numeric collection using the drop method ?

db.getCollection("2536464").drop();
true

Key Points

  • getCollection() is required because numeric names cannot use dot notation.
  • The drop() method returns true if the collection is successfully deleted.
  • All documents and indexes in the collection are permanently removed.

Conclusion

Use db.getCollection("numericName").drop() to remove collections with numeric names. The getCollection() method handles special characters that standard dot notation cannot process.

Updated on: 2026-03-15T00:45:41+05:30

209 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements