lookUp aggregation pipeline and text search

Hello, good day all,

I have used the lookUp aggregation pipeline to join 3 collections, is there a way to ignore null returns such that if one of the lookUp aggeration pipeline stage returns null, a response is sent for the stage which does not return null?

				{
					$lookup: {
						from: 'distributionchannels',
						localField: '_id',
						foreignField: 'feedbackId',
						as: 'distributionchannels',
					},
				},
				{
					$unwind: '$distributionchannels',
				},
				{
					$lookup: {
						from: 'feedbackquestions',
						localField: '_id',
						foreignField: 'feedbackId',
						as: 'feedbackquestions',
					},
				},
				{
					$unwind: '$feedbackquestions',
				},
				{
					$lookup: {
						from: 'feedbackresponses',
						localField: '_id',
						foreignField: 'feedbackId',
						as: 'feedbackresponses',
					},
				},

so if distributionchannels is found and feedbackresponses, feedbackquestions are not found, it should return the pipeline with distributionchannels found instead of returning an empty array

I have created a wildcard text index, I would love to know how partial search can be enabled i.e if I have the sentence " Hello World" and i search for “He” i should find “Hello World”

Hi @Seghosimhe_David,

Did you try using the preserveNullAndEmptyArrays option in your $unwind stage?
When it is set to false, $unwind does not output a document for null, missing, or an empty array.

If it doesn’t help, can you share a few example documents from all your collections along with the expected output from the pipeline?

If the aggregation pipeline is a frequently used query in your application, please consider changing your data model to accommodate this query better. Take a look at this Data Modeling guide and you can also consider taking our Free M320: Data Modeling course on MongoDB University.

Depending on your use case, if you’re using Atlas to manage your database deployment, please try Atlas Search.
However, if your database deployment is not hosted on Atlas, you could try $regex, which provides regular expression capabilities for matching strings pattern in queries.

If you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
MongoDB

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.