Google Groups

Re: unwinding - pairs, triplets ..


A. Jesse Jiryu Davis Apr 17, 2012 8:01 AM
Posted in group: mongodb-user
Consider something like this (for all pairs):

> db.foo.insert({t:[1,2,3]})
> db.foo.aggregate({$project:{s:'$t',t:'$t'}}, {$unwind:'$t'}, {$unwind:'$s'}, {$project:{combination:{0:'$s', 1:'$t'}}})

To do triplets, rename 't' to a third name in the first $project clause, add another $unwind clause, and include the third name in the 'combination' field in the final $project.

On Tuesday, April 17, 2012 9:06:16 AM UTC-4, Syd wrote:
Is there possibility of unwinding based on combinations. For example, I would like to unwind all possible pairs (or triplets etc..) from within an array instead of single element (which is the default behavior).

Thanks

On Tuesday, April 17, 2012 9:06:16 AM UTC-4, Syd wrote:
Is there possibility of unwinding based on combinations. For example, I would like to unwind all possible pairs (or triplets etc..) from within an array instead of single element (which is the default behavior).

Thanks