unwinding - pairs, triplets ..

67 views
Skip to first unread message

Syd Davenport

unread,
Apr 17, 2012, 9:06:16 AM4/17/12
to mongodb-user
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

Kristina Chodorow

unread,
Apr 17, 2012, 10:45:45 AM4/17/12
to mongodb-user
Can you give an example?

A. Jesse Jiryu Davis

unread,
Apr 17, 2012, 11:01:28 AM4/17/12
to mongod...@googlegroups.com
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

Syd

unread,
Apr 17, 2012, 4:12:44 PM4/17/12
to mongodb-user
Thanks. This is what I was looking for.

Below code also removes duplicates and same combinations ex. [1,1],
([1,2], [2,1]).

db.foo.aggregate({$project:{s:'$t',t:'$t'}}, {$unwind:'$t'},
{$unwind:'$s'}, {$project:{combination:{0:'$s', 1:'$t', dup: {$cmp:
["$s","$t"] } }}}, {$match: {'combination.dup': {$nin: [0, 1]}}});

A. Jesse Jiryu Davis

unread,
Apr 17, 2012, 4:43:19 PM4/17/12
to mongod...@googlegroups.com
Nice.

Syd

unread,
Apr 18, 2012, 10:46:18 AM4/18/12
to mongodb-user
And, doing this crashed our system due to memory outage. We are
reverting back to Pig for this operation.

Are there known performance issues with aggregation framework in the
2.1.1-pre unstable branch? Thanks

Sam Millman

unread,
Apr 18, 2012, 10:52:23 AM4/18/12
to mongod...@googlegroups.com
I don't know of any personally however I wouldn't use an unstable alpha build to setup something for production, that'd just be a crazy thing to do.

2.1 is mostly for testing only, if you find a bug it's prolly good to JIRA it.

--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.


A. Jesse Jiryu Davis

unread,
Apr 18, 2012, 11:09:40 AM4/18/12
to mongod...@googlegroups.com
Yes, please do file a ticket at jira.mongodb.org and tell us how to reproduce this error so we can debug it.
To unsubscribe from this group, send email to mongodb-user+unsubscribe@googlegroups.com.

Chris Westin

unread,
Apr 28, 2012, 9:09:25 AM4/28/12
to mongod...@googlegroups.com
There are some optimizations that haven't made it in yet.  You can see what they are by looking at the open SERVER tickets for component "Aggregation Framework"
Reply all
Reply to author
Forward
0 new messages