Reputation: 347
I'm trying to delete a MongoDb database document from Rails.
According to the mongodb docs, this is the way to do it:
db = Mongoid::Clients.default
collection = db[:oauth_access_tokens]
collection.delete_many({"resource_owner_id": "xxxxxxxxxxxxxx"})
Based on the result I get it should be fine:
<Mongo::Operation::Result:58395820 documents=[{"ok"=>1, "n"=>0, "opTime"=>{"ts"=>#<BSON::Timestamp:0x00000006f62380 @seconds=1500457271, @increment=1>, "t"=>2}, "electionId"=>BSON::ObjectId('xxxxxxxxxxxxxxxxx')}]>
But then if I find in the mongo shell:
db.oauth_access_tokens.find({resource_owner_id: ObjectId("00000111111")})
I still get the document when I should not.
Upvotes: 0
Views: 674
Reputation: 1680
Try:
collection.delete_many(:resource_owner_id => BSON::ObjectId("00000111111"))
Upvotes: 1