mongodb - finding values based on cartesian product of other values -
consider collection holding following:
{ "a": 0, "b": 0, "c": 8, "d": 7 } { "a": 0, "b": 0, "c": 10, "d": 2 } { "a": 1, "b": 0, "c": 2, "d": 4 } { "a": 1, "b": 0, "c": 5, "d": 9 } { "a": 0, "b": 1, "c": 4, "d": 11 } { "a": 0, "b": 1, "c": 12, "d": 4 } { "a": 1, "b": 1, "c": 3, "d": 2 } { "a": 1, "b": 1, "c": 0, "d": 1 }
i query collection such following (or similar) returned
{ "_id" : { "a" : 0, "b" : 0 }, "out" : [{c: 8, d: 7}, {c: 10, d: 2}] } { "_id" : { "a" : 1, "b" : 0 }, "out" : [{c: 2, d: 4}, {c: 5, d: 9}] } { "_id" : { "a" : 0, "b" : 1 }, "out" : [{c: 4, d: 11}, {c: 12, d: 4}] } { "_id" : { "a" : 1, "b" : 1 }, "out" : [{c: 3, d: 2}, {c: 0, d: 1}] }
db.collection.aggregate
using $group
seems handle cartesian product / possible combinations of grouping side of things, doesn't seem applicable trying do.
i looking see if there functionality built mongo facilitate this. otherwise, plan use db.collection.distinct
unique set of values each key. then, manually build cartesian products in scripting language x , generate individual queries there.
does mongodb provide solve problem?
Comments
Post a Comment