First of all, I am new to MongoDB, so this question may be quite simple to answer for some of you. I am trying to create an array or embedded document that includes existing fields from my collection. In order words, let's say I have a collection with the fields "borough", "street" and "zipcode". I would like to create an embedded document named, for example, "Location" and move to that document these three fields. Is this possible? The following is one of the many different ways I tried to achieve this:
db.cooking.aggregate([{$set:{"borough":"$borough", "street":"$street", "zipcode":"$zipcode"}},{$out:"Location"}])
Where I would then use the db.Location.copyTo(cooking) expression to add the data from the newly created aggregate collection "Location" to the main collection "cooking". Of course I would have to remove the existing three fields from the cooking collection since I have the same information in the embedded document Location to avoid having duplicate data.