Question

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.

Was it helpful?

Solution

If you are actually trying to remove the column from the database, you should make a migration to remove the column.

If you are trying to change a record to not have a last name you could do something like User.last.last_name = false and then save it.

OTHER TIPS

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')

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top