0

eg. Need to search on two fields - "name" and "text" for a string "Mercedes" in the given documents

{"_id":{"$oid":"5a9427648b0beebeb69579e7"},"name":"Mercedes Tyler","text":"Mercedes Benz"},

{"_id":{"$oid":"5a9427648b0beebeb69579e7"},"name":"Mercedes Haan","text":"Other"}

Search String : Mercedes

I desire output like -

{"customerName":[{"_id":{"$oid":"5a9427648b0beebeb69579e7"},"name":"Mercedes Tyler","text":"Mercedes Benz"},{"_id":{"$oid":"5a9427648b0beebeb69579e7"},"name":"Mercedes Haan","text":"Other"}], "car" :[{"_id":{"$oid":"5a9427648b0beebeb69579e7"},"name":"Mercedes Tyler","text":"Mercedes Benz"}] }

Here Mercedes is present in the value of field "name" in both the documnents, so I have to get those documents under customerName

Mercedes is present in the value of field "text" in just one document , so I have to get that document under car

I need a query which can give me the above result

Stennie
  • 63,885
  • 14
  • 149
  • 175
dman
  • 1
  • 1
  • Have you checked out [text search](https://www.mongodb.com/docs/manual/core/text-search-operators/)? – ray Apr 21 '22 at 17:46
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Apr 22 '22 at 05:37

0 Answers0