MongoDB cross join of collections using MapReduce -


i have 2 collections in mongodb

user

{ "_id" : objectid("..."), "type" : "user", "user_id" : "u1" } { "_id" : objectid("..."), "type" : "user", "user_id" : "u2" } { "_id" : objectid("..."), "type" : "user", "user_id" : "u3" } 

item

{ "_id" : objectid("..."), "type" : "item", "item_id" : "i1" } { "_id" : objectid("..."), "type" : "item", "item_id" : "i2" } { "_id" : objectid("..."), "type" : "item", "item_id" : "i3" } { "_id" : objectid("..."), "type" : "item", "item_id" : "i4" } 

i planning cross join yield following collection

user_item

{ "_id" : objectid("..."), "type" : "user_item", "item_id" : "i1", "user_id" : "u1", "score" : 0 } { "_id" : objectid("..."), "type" : "user_item", "item_id" : "i1", "user_id" : "u2", "score" : 0 } { "_id" : objectid("..."), "type" : "user_item", "item_id" : "i1", "user_id" : "u3", "score" : 0 } { "_id" : objectid("..."), "type" : "user_item", "item_id" : "i2", "user_id" : "u1", "score" : 0 } { "_id" : objectid("..."), "type" : "user_item", "item_id" : "i2", "user_id" : "u2", "score" : 0 } { "_id" : objectid("..."), "type" : "user_item", "item_id" : "i2", "user_id" : "u3", "score" : 0 } { "_id" : objectid("..."), "type" : "user_item", "item_id" : "i3", "user_id" : "u1", "score" : 0 } { "_id" : objectid("..."), "type" : "user_item", "item_id" : "i3", "user_id" : "u2", "score" : 0 } { "_id" : objectid("..."), "type" : "user_item", "item_id" : "i3", "user_id" : "u3", "score" : 0 } { "_id" : objectid("..."), "type" : "user_item", "item_id" : "i4", "user_id" : "u1", "score" : 0 } { "_id" : objectid("..."), "type" : "user_item", "item_id" : "i4", "user_id" : "u2", "score" : 0 } { "_id" : objectid("..."), "type" : "user_item", "item_id" : "i4", "user_id" : "u3", "score" : 0 } 

which can retrieve using following code

db.item.find(). foreach( function (i) { db.user.find(). foreach( function (u) { var row = {}; row.type = "user_item"; row.item_id = i.item_id; row.user_id = u.user_id; row.score = 0; db.user_item.insert(row); }); }); 

but problem method slow on large data (u=10,000, = 10,000). there way yield same output using map-reduce in mongodb , map-reduce faster (theoretically yes)?

note: there no foreign keys


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -