hey will the sort works for the string fields inside the $search stage for me only date fields are working and not the string fields

Hey Mahendra, welcome!

Might be helpful for you to share the search index definition so we can provide a bit more focused response… You can view or edit it in the Atlas UI → Search tab → Indexes → Edit JSON

You’ll probably want to append a $sort stage AFTER your $search stage… something like:

$search: { index: "default", text: { query: "example", path: "yourFieldName" } } }, { $sort: { "yourFieldName": 1 } }

While your example, Michael, will work - there’s an impedence mismatch between $search and successive stages, and stages like $group and $sort that consume all documents could cause a big performance hit. It’s best when using $search and needing to sort to do so with the sort options within the $search stage.

Closed on Apr 7

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

I’m currently working with a MongoDB collection where we have a field named customAttributes, which contains dynamic subfields that vary from customer to customer.

We are trying to enable wildcard search on these dynamic subfields using Atlas Search. Since the keys inside customAttributes are not consistent across documents, we attempted to use a dynamic mapping with wildcard support.

Could you please confirm the correct syntax for the search index definition that would:

  • Enable wildcard search on all subfields inside customAttributes
  • Work with dynamic keys
  • Use the appropriate keyword analyzer to support wildcard queries

If possible, could you share a sample index definition that would meet the above requirements?

my main need is to make it work like contains operator that can search with special character’s tooo