如何在我的map/reduce函数中调用mongodb?这是一个好习惯吗? [英] How to call to mongodb inside my map/reduce functions? Is it a good practice?

查看:40
本文介绍了如何在我的map/reduce函数中调用mongodb?这是一个好习惯吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否:

  • 首先:是否可以在我的map/reduce函数中使用mongodb函数,例如:

  • 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.

    或者,也许我可以为此特定属性设置habtm关系吗?

    Or maybe, can I set a habtm relationship on this specific property?

    谢谢!

    推荐答案

    尽管可以从MR的db对象中调用方法,但不建议这样做,因为它不能与分片一起正常工作. 使用分片,您将只能访问分片本地的文档. 如果可能,应在客户端进行这种加入".

    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.

    这篇关于如何在我的map/reduce函数中调用mongodb?这是一个好习惯吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆