1

I have a document with a nested array of objects with a long list of properties. Instead of searching through the documents, I need a search inside one document's nested data.

(nested properties have indexes like 'data.$**': 'text')

Document item:

    "_id": "...",
    "data": [
         {
            "name": "Bob"
            ... 
         },
         {
            "name": "Mark" 
            ...
         },
         {
            "name": "John"
            ... 
         }
      ]
    }

Some wrong example of code for explaining what I want (cause error '...$text is only allowed...')

   const foundData = await this.fileModel
      .aggregate(
        [
          { $unwind: '$data' },
          { $match: { $text: { $search: "Mark" } } },
        ])
      .exec();

Without $unwind it will work of course but will return whole objects in array.

Needed result

    "_id": "...",
    "data": [
         {
            "name": "Mark" 
            ...
         }
      ]
    }

P.S: Solutions like this and this is not ok, since I don't want listed hundreds of properties...

0

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.