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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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 theDBRefclass 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.