Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove key fields

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.

like image 874
Christian Fazzini Avatar asked Nov 28 '22 01:11

Christian Fazzini


2 Answers

Using mongoid: User.last.unset('last_name') should do the trick.

like image 187
Gautam Rege Avatar answered Nov 29 '22 16:11

Gautam Rege


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

like image 24
monfresh Avatar answered Nov 29 '22 15:11

monfresh