Rohindra Yadav
Rohindra Yadav

Reputation: 89

Query for MongoDB

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}
 )

Upvotes: 0

Views: 158

Answers (3)

Adnan Ahmed Ansari
Adnan Ahmed Ansari

Reputation: 326

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.

Upvotes: 0

Lemix
Lemix

Reputation: 2920

db.posts.remove({"id": { "$gte": 1, "$lte":1000 }});

Upvotes: 2

Senthur Deva
Senthur Deva

Reputation: 787

You can use this query

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

Upvotes: 0

Related Questions