1

I have document collection in mongoDB database captioned 'internal-metrics'. I want to empty this collection to fill it with fresh data.

I tried using db.collection.deleteMany() and db.collection.remove() methods but both responded with following message.

2019-06-14T11:22:26.132+0530 E QUERY    [js] ReferenceError: metrics is 
not defined :
@(shell):1:1

The same method worked for document collection captioned 'student'.

MongoDB Enterprise TestCluster-shard-0:PRIMARY> use DevDatabase
switched to db DevDatabase
MongoDB Enterprise TestCluster-shard-0:PRIMARY> show tables
assessment
assignment
assignment-configuration
internal-metrics
knowledge-base
response
rubric-master
student
MongoDB Enterprise TestCluster-shard-0:PRIMARY> db.internal- 
metrics.deleteMany({})
2019-06-14T11:21:15.779+0530 E QUERY    [js] ReferenceError: metrics is 
not defined :
@(shell):1:1
MongoDB Enterprise TestCluster-shard-0:PRIMARY> db.internal- 
metrics.remove()
2019-06-14T11:22:26.132+0530 E QUERY    [js] ReferenceError: metrics is 
not defined :
@(shell):1:1
MongoDB Enterprise TestCluster-shard-0:PRIMARY> db.student.deleteMany({})
{ "acknowledged" : true, "deletedCount" : 6 }
MongoDB Enterprise TestCluster-shard-0:PRIMARY> db.internal- 
metrics.remove({})
2019-06-14T11:23:50.269+0530 E QUERY    [js] ReferenceError: metrics is 
not defined :
@(shell):1:1
MongoDB Enterprise TestCluster-shard-0:PRIMARY> db.internal- 
metrics.remove({})
2019-06-14T11:27:25.946+0530 E QUERY    [js] ReferenceError: metrics is 
not defined :
@(shell):1:1

I expect the collection to be emptied using the method on mongoDB shell.

2 Answers2

3

You have to try the following pattern db.getCollection('internal-metrics').remove({})

2

Try :

db.getCollection('internal-metrics').remove({})

or,

db['internal-metrics'].remove({})
Ravi Shankar Bharti
  • 8,922
  • 5
  • 28
  • 52