I got a collection of only three documents. I want to use the autocomplete functionality on the “name” field of my documents. This is the structure of the documents:
{
"_id": {
"$oid": "61897bb2747e2cb1f0f55f4d"
},
"genre": ["Platforms", "Aventure"],
"languages": ["Spanish", "English"],
"name": "mario bros",
"ageCategory": "A - (Todo publico)",
"releaseDate": {
"$date": {
"$numberLong": "1223769600000"
}
},
"synopsis": "El mejor videojuego del mundo",
"createdAt": {
"$date": {
"$numberLong": "1632533182852"
}
},
"updatedAt": {
"$date": {
"$numberLong": "1632533182852"
}
},
"__v": {
"$numberInt": "0"
},
"platforms": ["PC", "Nintendo Wii", "X-box 360"]
}
This one’s name is “mario bros”. The others are “Hallo” and “candy crush”.
So I created the search index with the JSON editor, following this tutorial on the MongoDB youtube channel: Building an Autocomplete Form Element with Atlas Search and JavaScript - YouTube
And this was the result:
{
"mappings": {
"dynamic": false,
"fields": {
"name": [
{
"foldDiacritics": false,
"maxGrams": 7,
"minGrams": 3,
"tokenization": "edgeGram",
"type": "autocomplete"
}
]
}
}
}
The index was created successfully, but when I tried “mario” and “Hallo”, no documents were returned.
Also, when I click on View Query Syntax, I get this:
[
{
$search: {
index: 'default',
text: {
query: 'mario',
path: {
'wildcard': '*'
}
}
}
}
]
I was expecting the value of “path” to be “name”. I dont’ know if it has something to do with my problem.
I also tried creating indexes with the View editor and it worked once but never again (I remember seeing something like 0.6 of score but I don’t even remember which term I searched). I’ve tried setting minGrams to 4, as I remember reading somewhere in the docs that it was the recommended number, and setting maxGrams to a higher number (15 and 20), just to see if the result was different, but nothing worked.
Did I set something wrong? Am I misunderstanding how Atlas Search or the autocomplete functionality work?