Wildcard search using MongoDB Compass

Hello,

I am trying to do a wildcard search using MongoDB compass and doesn’t seem to work.

I am using Atlas to create a full text search index.

{
  "mappings": {
    "fields": {
      "llt_name": {
        "analyzer": "lucene.standard",
        "type": "string"
      }
    }
  }
}

Using Mongo Compass to write wildcard search and doesn’t seem to work.

[{
    $search: {
        search: {
            query: 'lymph*',
            path: 'llt_name',
            wildcard: true
        }
    }
}, {
    $project: {
        llt_code: 1,
        _id: 0,
        score: {
            $meta: "searchScore"
        }
    }
}, {
    $limit: 100
}]

Any ideas?

Got it to work by using wildcard keyword.

[{$search: {
  "wildcard": {
    query: 'lymph*',
    path: 'llt_name',
    allowAnalyzedField:true
    }
}}]

Hi, Supriya! Glad you got it to work! I actually talked about exactly this case on a presentation I just recorded yesterday. Here is when I talk about building out the stages for fuzzy, autocomplete and wildcard: In [Atlas] Search of Your Even Better FIFA Dream Team - YouTube

Hope it helps!

2 Likes

Thanks @Karen_Huaulme!!
I have a question around fuzzy matching. It works nice using text and fuzzy keywords when searching for 1 word. How do we get the fuzziness to work in a phrase?

Thanks,
Supriya

Hi Supriya,

I apologize for the delay. I did not see this message. You should play around with maxEdits and maxExpansions options which work on each term in the string: https://docs.atlas.mongodb.com/reference/atlas-search/text/

Thank you,

Karen