If you remove an object attribute, is it deleted from the database?

Yes, it be. Remove the attribute and then re-save() the object.

In MongoDB, if you remove an attribute (field) from a document using an update operation with the $unset operator or by any other means, the attribute will be removed from that specific document, but the document itself will still exist in the database.

The removal of an attribute is specific to the document, and it doesn’t affect the entire structure of the document or the collection. Other documents in the same collection can still have the attribute.

To clarify, here’s an example using the $unset operator:

db.collection.update(
{ _id: yourDocumentId },
{ $unset: { attributeName: 1 } }
);

After this operation, the attributeName will be removed from the document with the specified _id. The document will still exist in the collection, but that particular attribute will no longer be present in that document.

If you want to remove the entire document, you would use the remove or deleteOne method:

db.collection.remove({ _id: yourDocumentId });

This will delete the entire document from the collection.