Wide to long transformation in aggregation

From: Boyd Skelton <boydskelton@xxxxxxxxx>
To: mongodb-user <mongodb-user@xxxxxxxxxxxxxxxx>
Date: Wed, 20 Apr 2016 06:48:54 -0700 (PDT)
Why ads?
I am working with a dataset that looks like this:

asset, start_date, end_date, ship_date
"A", 2015-01-01, 2015-02-01, 2015-03-01
"B", 2015-02-01, 2015-02-15, 2015-03-01

Ultimately, I would like to aggregate the data to produce the following:

[{
  _id : {
    year: 2015,
    month: 1
  }, 
  start:1,
  end: 0,
  ship: 0
},
{
  _id : {
    year: 2015,
    month: 2
  }, 
  start: 1,
  end: 2,
  ship: 0
},
{
  _id : {
    year: 2015,
    month: 2
  }, 
  start: 0,
  end: 0,
  ship: 2
}]

My thought is to use $project, $addToSet, and $unwind; but is there a 
better way?

Thank you.

-- 
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.org/manual/support/
--- 
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@xxxxxxxxxxxxxxxx.
To post to this group, send email to mongodb-user@xxxxxxxxxxxxxxxx.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/529aee06-0bd1-4f54-bc52-7fe6e5374037%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Why ads?