问题
I would like to know if:
Firstly: Is it possible to use mongodb functions inside my map/reduce functions, for example:
function() { foo = db.myCollection.find({ _id: ObjectId('4ee235ce002c62f393000008')}) print(foo); # returns 'db.myCollection -> undefined' }
Secondly: Is it a good practice? For example, I need to map a specific property from the documents referenced for a 'root' document.
Or maybe, can I set a habtm relationship on this specific property?
Thanks!
回答1:
although it is possible to call methods from the db object from MR, it is not recommended since it does not work properly with sharding. With sharding you would only be able to access documents that are local to the shard. If possible this kind of "joining" should be done client side.
来源:https://stackoverflow.com/questions/8472769/how-to-call-to-mongodb-inside-my-map-reduce-functions-is-it-a-good-practice