简体   繁体   中英

How do I associate specific documents in a collection in MongoDB-atlas to documents that are stored in a different collection in the same cluster?

I was wondering if it is possible to associate documents that are stored in a collection in mongoDB-ATLAS to a specific document in a different collection in the same cluster.

I am trying to display user-specific data on a web-page when a user logs into an account. So if a user enters data into a survey form in their homepage of my application, it is stored in a separate collection to where the users data is stored. I would like the survey data that a specific user has entered, to display in a table on the specific users homepage, so only they can see their own data they have entered previously. but I am not sure know how to associate the survey data to specific accounts since they are in different collections? Does anyone have any advice? Many thanks in advance.

You can make use of aggregation pipelines to achieve this. Aggeregation pipeline is similar to joins feature in SQL.

Please refer to documentation: https://docs.mongodb.com/manual/core/aggregation-pipeline/index.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM