为什么MongoDB文档建议不要使用DBREF? [英] Why do the MongoDB docs recommend not using DBREFs?

查看:469
本文介绍了为什么MongoDB文档建议不要使用DBREF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用于DBREF的MongoDB文档说:

除非您有令人信服的理由使用DBRef,否则请改为使用手动引用.

Unless you have a compelling reason to use DBRefs, use manual references instead.

为什么? DBREF似乎更易于使用,因为它们对数据库和集合名称进行了编码,这将减少应用程序中的硬编码.另外,DBREF是许多驱动程序都可以理解的标准格式.

Why? DBREFs seem more easy to use, since they encode the database and collection names, which would lead to less hard-coding in the application. Plus, DBREF is a standard format that many drivers understand.

这个问题是相关的,但不完全相同:

This question is related, but not exactly the same:

MongoDB-DBREF是否必要?

该问题的答案是嵌入/非规范化比链接更可取,但是它不能回答为什么手动链接比DBREF更可取的问题.

The answer to that question is that embedding/denormalization is preferable to linking, but it doesn't answer the question of why manual linking is preferable to DBREFs.

推荐答案

以下是我查看过的所有内容的结论.

Here a conclusion of all I viewed.

使用DBRef不是join操作,它将自动查询第二次或更多次,具体取决于您在此收集字段中获得的DBRef的数量.

Using DBRef is not a join operation, it will automatically query the second or more times, depends on how much DBRef you have got in this collection fields.

假设您有一个其模型具有10个DBRef的集合,则查询它的10个元素的列表,而这些DBRef之一是really needed.查询后,无论是否需要这些DBRef,Mongodb都会自动运行101(1 + 10*10)查询.如果您手动查询这些字段,则只需进行少量编码,仅需要11(1 + 1*10)查询.

Assuming you have a collection that its model has 10 DBRef, you make query for 10 elements' list of it and one of these DBRef is really needed. Once you query, Mongodb will runs 101(1 + 10*10) queries, automatically, no matter you need these DBRef or not. If you query these field manually, just a few coding and only 11(1 + 1*10) queries are needed.

那你怎么说?

这篇关于为什么MongoDB文档建议不要使用DBREF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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