I know how to delete documents in a collection. i.e. User.last.delete
In the User
document. I have the following keys: first_name
, last_name
, gender
.
Lets say , I decide to remove the key last_name
. So I would have first_name
and gender
only. How would I go about this? Is this even possible?
I tried User.last.last_name.delete
to no avail.
Using mongoid: User.last.unset('last_name') should do the trick.
If you want to remove the last_name
field from the entire collection (from all the documents in the collection), you would do User.all.unset('last_name')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With