Reputation: 1105
I have several collections in my db.
I need to create a separate collection by getting the fields from different collections something like views in relational tables.
Is there any way to do it in mongodb?
Upvotes: 0
Views: 83
Reputation: 69663
MongoDB doesn't support views. You have to implement this functionality yourself on the application layer.
Upvotes: 1
Reputation: 534
Aside from the DBCollection.find(...)
allowing a subset of keys to be outputted in the query results, it sounds like you really want to do SQL table joins. You can't do a direct join, but you can use the DBRef
class to simulate something similar to a SQL join. Also, you can't really do SQL unions, as it's expected that related sets of attributes will be in the same collection.
You might want to check out this SQL to MongoDB Mapping Chart. In general, it's important to remember that MongoDB is schema-less, so you're not tied to using the same column/row structure for each document. Thus, constructs like views might not be as important when a schema isn't enforced.
Upvotes: 2