0

How to remove a document in MongoDB where I want to remove id 1 to 1000, In the collection, I have 10 million documents.

db.posts.remove(
 { "id": 1 to 1000}
 )
  • 1
    Possible duplicate of [How to delete N numbers of documents in mongodb](https://stackoverflow.com/questions/19065615/how-to-delete-n-numbers-of-documents-in-mongodb) – Ashh Sep 29 '18 at 09:36

3 Answers3

2
db.posts.remove({"id": { "$gte": 1, "$lte":1000 }});
Lemix
  • 2,415
  • 1
  • 15
  • 16
0

You can execute the command below on shell

db.posts.deleteMany({$and: [{"id": { $gte: 1} }, {"id": { $lte: 1000} }] )

For reference, you can also visit MongoDocs.

Pang
  • 9,564
  • 146
  • 81
  • 122
0

You can use this query

db.posts.remove({"$and" : [{"id" :{"$gte" :1}},{"id" :{"$lte" :1000}}]})
Senthur Deva
  • 737
  • 4
  • 12