Mongo Atlas: Index build failed, Error provided: Unknown error

Hello,

I am trying to add a text index on our cluster. But we received (in the activity) an

Index build failed, Error provided: Unknown error
 client-graph-XXX
Index Name: XXX
Database: XXXX
Collection: XXXX
Index Build Type: Background

The collection is not that big (113MB) we have 2GB of RAM and 20GB of Storage far from being used.

What can we do here? of course, the Index creation works well locally.

Honestly, it looks like a bug, it appears and then disappears:

Thanks

Hi @Sebastien_Morel,

Few questions here:

  1. How did you build the index (via Data Explorer, mongosh, driver?)
  2. Is there any array fields in the collection you are indexing that are also included in the compound text index?

It’s possible you may have hit one of the following Text Index Restrictions. Look forward to hearing from you.

In saying so, the lack of error details does appear odd. I’ll run some tests on my end to see if I can hit the same error based on the restrictions via Data Explorer.

Regards,
Jason

@Sebastien_Morel - I did manage to get Unknown Error when creating a compound text index which included a field that was an array:

Index build failed, Error provided: Unknown error
TestCluster
Index Name: name_text_c_1
Database: textdb
Collection: collection
Index Build Type: Background

Wondering if this is the same for you? I’ll raise this with the team to see if this error can be more detailed in future

Regards,
Jason

hey @jason,

Thanks, I have double-checked with

db.getCollection("collection").find({
    name:  { $exists: true, $type: 'array' }
})

And no document has a name that would be an array they are all string

Also, the compound is not required to trigger the problem a simple:

createIndex({ name: 'text'})

triggers the unknown error

Thx

Interesting - The index name and details in your initial post seem to indicate this isn’t the same index (looks to be a compound index with tenanId, language, etc. Unless you have changed the name of it to include those?):

Can you run the following on the same collection and advise the output? db.collection.getIndexes() replacing collection with the collection name where the error is occuring. Also, when you state the trigger for the error, are you running that command via mongosh?

Regards,
Jason

Also, I assume "collection" in the above has been redacted for the purposes of this post but just wanted to verify? It may not be the name field too. As advised in my previous response, the index in your screenshot shows that the index is a compound index which has more than just name field specified.

Regards,
Jason

the compound is what I need. But I did many tries to isolate the issue.
And I can say that the simple

createIndex({ name: 'text'})

triggers the “unknown error”.

I have many indexes on that collection (18),

But again I have a replica locally with Docker (not with the same data but the same indexes etc.) and no problem.

It seems to be an issue on Atlas only.

Also in my screenshot, it’s visible that Atlas is trying to create the Index then it fails and disappears,

I hope it helps

EDIT: yes I staged I correctly replaced the collection name in my query :slight_smile: I also replace the type “array” by type “string” to make sure of the validity of that query.

@Sebastien_Morel - Thanks for providing those details. There’s a few things I need to clarify below.

Please share the actual index you are trying to create.

Are you doing this from Atlas UI or from mongosh? Can you please send a screenshot of this creating the error? It would be good to see where you are getting this error itself. If it’s from the Project Activity feed, please provide a screenshot of that where the non-compound text index you specified - I imagine if {name: 'text'} is causing the error, the project acitivity feed should show something like:

Index build failed, Error provided: Unknown error
<>
Index Name: name_text /// <-- as opposed to the compound index name in your initial screenshot
Database: db
Collection: collection
Index Build Type: Background

The query you provided before seems to be checking for the name if it’s an array type. Can you advise what you tried here to check the validity? I think it would be better to try troubleshoot this with the full compound array index as opposed to the standard text index as that is what you would be creating in the end either way. The error which I received on my end was from another field (not name) which was an index. The query you provided previously was only searching on the name field. It would be better to get an understanding of what other fields are inside the collection since it may be hitting a text index restriction.

Lastly, please provide the output from db.collection.getIndexes() as well.

Please redact all sensitive and personal information before posting.

On my test collection, the same query whether using $type of 'array' or 'string' doesn’t indiciate the other fields being array or not:

textdb> db.collection.find({name:{$exists:true,$type:'string'}})
[
  {
    _id: ObjectId('6578ef21ca7d32efb0853a5e'),
    name: 'test',
    c: [ 1, 2, 3, 4, 5 ]
  }
]

It returned the document since name field exists and it’s of type string. However, we can see that field c is the array.

If you know a field is an array (possibly relating to the index you’re trying to create), you can try with those fields instead. For example, for checking the field c:

textdb> db.collection.find({c:{$type:'array'}})
[
  {
    _id: ObjectId('6578ef21ca7d32efb0853a5e'),
    name: 'test',
    c: [ 1, 2, 3, 4, 5 ]
  }
]

Can you also check with anyone else with access to the Atlas project if they attempted to create the compound index in the past? It could possibly be that they have done it initially and is creating the error. Maybe not but it would be good to check.

hello,

So we figured it out. The problem was that we have a language field in the collection with more language than MongoDB can handle. https://www.mongodb.com/docs/v6.0/tutorial/specify-language-for-text-index/#specify-the-default-language-for-a-text-index

Creating the index with language_override: 'nameIdxLanguage' even though that field does not exist fixed our issue and the index was successfully create

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