when I call
db.collection.remove({\'condition\':\'some condition\'});
This one line will delete all the matching condition documents.
You need to perform two separate queries for this
take only one item from the matching filters
var item = db.collection.findOne({'condition':'some condition'})
and delete the item by using the id
db.collection.remove({_id: item._id});
Can't you just run a find first to get the id then a delete when you have the one you want?
db.collection.remove
now has a justOne
flag
http://docs.mongodb.org/manual/reference/method/db.collection.remove/#db.collection.remove
If there are multiple records and you want to delete only first record, then set justOne parameter in remove() method.
Here, you want to delete only 1. Thus, set "justOne" parameter as 1.
db.collection.remove({'condition':'some condition'},1);
To remove one document from collection use the bellow command
db.collectionname.remove({"_id": ObjectId("5473293d43ecdre56352457f3a")})
Try this one for delete.
db.users.deleteOne({"_id": ObjectId("5473293d43ecdre56352457f3a")});