SQL view in mongodb

Viewed 12453

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:

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:

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.

This can be accomplished by Views in SQL correct? Can I accomplish this kind of functionality in MongoDb?

4 Answers

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

In addition to this answer, mongodb now has on-demand materialized views. In a nutshell, this feature allows you to use aggregate and $merge (in 4.2) to create/update a quick view collection that you can query from faster. The strategy is used to update the quick view collection whenever the main collection has a record change. This has the side effect unlike SQL of increasing your data storage size. But the benefits can be huge depending on your querying needs.

Related