0

I have an object and I want to query if this term exists within the object and if yes return it. I don't know the term which will be used to query. Let's assume I queried answer1 then return it

response:{
 "101": "answer1",
  "201": "answer2",
  "301": "answer3",
  "100": "answer4",
  "200": "answer5",
  "300": "answer6",
  "111": "answer7",
  "211": "answer8",
  "311": "answer9"
}

TIA

1 Answer 1

1

Try this way:

db.collection.createIndex( { '$**' : "text" } )
db.collection.aggregate([{$match : { $text: { "$search": "answer1" } }}])

Here we are creating the indexes with text and then doing a text search.

Hope this helps you!

Sign up to request clarification or add additional context in comments.

Comments

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.