Scott
Scott

Reputation: 330

Mongoid doesn't delete Mongo objects

I am using Sinatra and Mongoid to access a MongoDB. Most of it works well except when I try to delete an object, the object gets deleted but appears to remain in the database.

 u = User.find(user_id)
 u.delete

This seems to work and does not generate an error, but when I check the database using the Mongo console to confirm this, the object is still there. The user object is not in a capped collection.

 u = User.find(user_id)
 u.delete
 u = User.find(user_id)

This change does generate an error, which means the object was successfully deleted. Nonetheless, in the Mongo console, a find() call on the users collection still shows the object.

Upvotes: 2

Views: 1393

Answers (1)

Lior
Lior

Reputation: 60

While the MongoDB object is not erased from the database, a "deleted_at" parameter is added to the object which indicates when it was "deleted". Afterward the object will not be found in searches.

Upvotes: 1

Related Questions