Updating document field based on aggregation

23 views
Skip to first unread message

jbis2k

unread,
Mar 18, 2018, 5:46:43 PM3/18/18
to mongodb-user
db.Collection.aggregate(
   [
     {
       $project:
         {
            yearMonth: { $month: "$Date" }
         }
     }
   ]
)


I would like to store the value of $month into the yearMonth field within my collection for all documents upon evaluation.  The online documentation seems vague in how this is explained and online examples seem not to work.  Can anyone please point me in the right direction?

I even tried the following to no avail:

db.Collection.update (
    { "$set": {"yearMonth": { $month: "$Date" }}},
    {"multi": true}
    )

John Berosh

unread,
Mar 20, 2018, 12:36:41 AM3/20/18
to mongodb-user
Solved.  
Reply all
Reply to author
Forward
0 new messages