mongodb中的SQL视图 [英] SQL view in mongodb
问题描述
我目前正在为一个已经开始的项目评估mongodb,但是我找不到任何有关mongodb中SQL视图的信息. SQL视图提供的我需要的是将来自不同表(集合)的数据集中到一个集合中.
I am currently evaluating mongodb for a project I have started but I can't find any information on what the equivalent of an SQL view in mongodb would be. What I need, that an SQL view provides, is to lump together data from different tables (collections) into a single collection.
我只希望将一些文档聚在一起并将它们标记为一个文档.这是一个示例:
I want nothing more than to clump some documents together and label them as a single document. Here's an example:
我有以下文件: cc_address us_address 帐单地址 送货地址
I have the following documents: cc_address us_address billing_address shipping_address
但是在我的应用程序中,我想查看我的所有地址,并能够在一个文档中对其进行管理.
But in my application, I'd like to see all of my addresses and be able to manage them in a single document.
在其他情况下,我可能只想要集合中的几个字段:
In other cases, I may just want a couple of fields from collections:
我有以下文件: fb_contact twitter_contact google_contact reddit_contact
I have the following documents: fb_contact twitter_contact google_contact reddit_contact
这些文档中的每一个都具有对齐的字段,例如名字,姓氏和电子邮件,但它们也具有不对齐的字段.我希望能够将它们编译成仅包含对齐字段的单个文档.
each of these documents have fields that align, like firstname lastname and email, but they also have fields that don't align. I'd like to be able to compile them into a single document that only contains the fields that align.
这可以通过SQL中的View完成吗?我可以在MongoDb中完成这种功能吗?
This can be accomplished by Views in SQL correct? Can I accomplish this kind of functionality in MongoDb?
推荐答案
问题已经很老了.但是,从mongodb v3.2开始,您可以在 $ lookup 中使用只要将集合不分片,就可以将不同集合的数据连接在一起. 从mongodb v3.4开始,您还可以创建只读视图.
The question is quite old already. However, since mongodb v3.2 you can use $lookup in order to join data of different collections together as long as the collections are unsharded. Since mongodb v3.4 you can also create read-only views.
这篇关于mongodb中的SQL视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!