How to call to mongodb inside my map/reduce functions? Is it a good practice?

北慕城南 提交于 2020-01-13 17:57:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!