本文介绍了MongoDB-手册参考示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读手册参考部分. MongoDB数据库参考文档,但是我真的不理解第二次查询来解析参考字段"的部分.您能给我一个这个查询的例子吗,这样我就可以更好地了解他们在说什么.

I was reading the manual references part from the MongoDB Database References documentation, but I don't really understand the part of the "second query to resolve the referenced fields". Could you give me an example of this query, so i can get a better idea of what they are talking about.

推荐答案

在您所指的手册部分中,该文档非常清晰,其中数据库参考.理解这一点中最重要的部分包含在页面的开头声明中:

The documentation is pretty clear in the manual section you are referring to which is the section on Database References. The most important part in comprehending this is contained in the opening statement on the page:

更多信息涵盖了您如何可能选择处理存储在另一个集合中的数据的主题.

The further information covers the topic of how you might choose to deal with accessing data that you store in another collection.

DBRef 可以在某些驱动程序中实现规范(),而无需过多详细说明,因此可以在您的文档中找到这些规范时自动将引用的文档检索(展开)到当前文档中.这将在幕后"中实现,并对该集合中的_id文档进行另一个查询.

There is the DBRef specification which without going into too much more detail, may be implemented in some drivers as a way that when these are found in your documents they will automatically retrieve (expand) the referenced document into the current document. This would be implemented "behind the scenes" with another query to that collection for the document of that _id.

对于 手册参考 这基本上是说文档中只有一个字段,该字段的内容来自另一个文档的 ObjectId .这仅与DBRef不同,因为基本驱动程序实现将从不进行处理,这将使您可以自行处理其他文档的进一步检索.

In the case of Manual References this is basically saying that there is merely a field in your document that has as it's content the ObjectId from another document. This only differs from the DBRef as something that will never be processed by a base driver implementation is leaves how you handle any further retrieval of that other document soley up to you.

在以下情况下:

> db.collection.findOne()

{
   _id: <ObjectId>,
   name: "This",
   something: "Else",
   ref: <AnotherObjectId>
}

文档中的ref字段只不过是一个普通的ObjectId,并且没有什么特别的.这允许您执行的操作是提交自己的查询以获取所引用的对象详细信息:

The ref field in the document is nothing more than a plain ObjectId and does nothing special. What this allows you to do is submit your own query to get the Object details this refers to:

> db.othercollection.findOne({ _id: <AnotherObjectId > })
{
  _id: <ObjectId>
  name: "That"
  something: "I am a sub-document to This!"
}

请记住,所有这些过程都是通过驱动程序API在客户端进行的.在任何情况下,获取其他文档的任何操作均不会在服务器上发生.

Keep in mind that all of this processes on the client side via the driver API. None of this fetching other documents happens on the server in any case.

这篇关于MongoDB-手册参考示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 18:34