Details
-
Improvement
-
Resolution: Gone away
-
Unknown
-
None
-
None
-
None
-
None
Description
I have a collection with a text index and an additional field called schemaId. For some of my queries this queries this is required and for some other queries it is preferred to return results from the same schemaId. Therefore I created my index like that:
it is a large collection, therefore i use small field names. Saved a few Gigs.
await collection.Indexes.CreateOneAsync(
|
new CreateIndexModel<MongoTextIndexEntity<List<MongoTextIndexEntityText>>>( |
Index // just a shortcut for Builder<>.Index |
.Ascending(x => x.SchemaId)
|
.Text("t.t") |
.Text(x => x.SchemaId),
|
new CreateIndexOptions |
{
|
Weights = new BsonDocument |
{
|
["t.t"] = 2, |
["s"] = 1 |
}
|
}),
|
cancellationToken: ct);
|
Or I would like to do that. But I get the following error:
> The index keys definition contains multiple values for the field 's'. (SchemaId)
But this is a restriction of the driver, not of MongoDB.
The problem is, that the field names are not used for the index definition. Instead the following index is created:
{
|
"v" : 2.0, |
"key" : { |
"a" : 1.0, |
"s" : 1.0, |
"_fts" : "text", |
"_ftsx" : 1.0 |
},
|
"name" : "a_1_t.t_text_s_text", |
"weights" : { |
"s" : 1.0, |
"t.t" : 1.0 |
},
|
"default_language" : "english", |
"language_override" : "language", |
"textIndexVersion" : 3.0 |
}
|
|
Therefore this limitation does not really exist. But I am not sure if this depends on specific versions of MongoDB or not.