How to join two collections

intent = [
{
“_id”: {
“$oid”: “64d872cfb050fa5efbcd5501”
},
“name”: “Account_Opening_Documents”,
“created”: {
“$date”: “2023-06-19T12:22:01.755Z”
},
“updated”: {
“$date”: “2023-08-14T08:10:17.081Z”
},
“examples”: [
“64d9e169545a6aa086e2a119”,
“64d9e169545a6aa086e2a11a”
],
“description”: “testing”
}
]

example = [
{
“_id”: {
“$oid”: “64d9e169545a6aa086e2a119”
},
“text”: “hello”,
“created”: {
“$date”: “2023-08-07T08:47:41.860Z”
},
“updated”: {
“$date”: “2023-08-09T13:30:26.467Z”
}
},
{
“_id”: {
“$oid”: “64d9e169545a6aa086e2a11a”
},
“text”: “What are the documents required in opening an account?”,
“created”: {
“$date”: “2023-06-19T12:22:01.755Z”
},
“updated”: {
“$date”: “2023-06-19T12:22:01.755Z”
}
}
]

How could I join two collections for query in mongodb ?

Hello, @Md_Asif_Kabir_Emon and welcome to the MongoDB community! :wave:

Blockquote
How could I join two collections for query in mongodb ?

Well, in your case, I think $lookup stage of the aggregation pipeline is what you’re looking for.
Additionally, I’d recommend to read about data modelling in MongoDB - maybe you won’t need two collections and, therefore, merging them :wink:

Also, it is better to format your code examples before posting. This way your topic will be easier to read and more people will be willing to help you.

1 Like