[SERVER-32720] Field xxx of text index contains an array in document Created: 16/Jan/18  Updated: 22/Feb/18  Resolved: 17/Jan/18

Status: Closed
Project: Core Server
Component/s: Index Maintenance
Affects Version/s: 3.6.0, 3.6.1, 3.6.2
Fix Version/s: None

Type: Question Priority: Major - P3
Reporter: Phillip Wirth Assignee: Mark Agarunov
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-27392 text index with multi-key prefix is n... Closed
Participants:

 Description   

Hi,

why can't text indexes not contain an array anymore?

Document:

> db.employee.findOne()                             
{                                                                                                  
        "allUnitIds" : [                            
                "054edeaf-5efd-43b8-abe2-04164d9071a5"                                                   
        ],                                          
        "allSearchableStrings" : "..."                 
}      

Indexcreation

> db.employee.createIndex({ "allSearchableStrings" : "text" , "allUnitIds" : 1})                         
{                                                   
        "ok" : 0,                                   
        "errmsg" : "Field 'allUnitIds' of text index contains an array in document: { _id: \"2d937bbf-8a4f-4688-8821-a951971ba5e6\", allUnitIds: [ \"054edeaf-5efd-43b8-abe2-04164d9071a5\" ], allSearchableStrings: \"...\" }",
        "code" : 201,                               
        "codeName" : "CannotBuildIndexKeys"         
}  

It was at least possible with 3.4.x



 Comments   
Comment by Phillip Wirth [ 23/Jan/18 ]

@David Storch as noted before a changelog hint would be nice, thanks for the the link in the documentation by btw

Comment by David Storch [ 22/Jan/18 ]

Hi pwirth,

My apologies that you ran into this issue. We do document that the non-text fields of a text index cannot be multikey here:

https://docs.mongodb.com/manual/core/index-text/#compound-index

A compound text index cannot include any other special index types, such as multi-key or geospatial index fields.

Is there anything that we could do to clarify this point in the documentation?

Best,
Dave

Comment by Ramon Fernandez Marina [ 20/Jan/18 ]

Hi pwirth,

sorry to hear you run into this issue. Unfortunately, at the moment we're not able to label any fixes to existing bugs or undefined behaviors as "breaking changes", and that's why you don't see them in the release notes on in the changelog. However our bug tracking system is public, which allows anyone to find and track any such fixes or changes that might impact them.

We'll revisit this issue to see if we can do a better job at flagging any tickets that may change previously buggy / undefined behavior that users may have been relying on.

Regards,
Ramón.

Comment by Phillip Wirth [ 18/Jan/18 ]

@Mark Agarunov

well than please note it in the changelogs as well as in the documentation regarding text indexes since this is a breaking change.

Comment by Mark Agarunov [ 17/Jan/18 ]

Hello pwirth,

Thank you for the additional information. My apologies, I initially misunderstood the request. After looking into this and reproducing the behavior you've described, I believe this was due to the change made in SERVER-27392. As stated in Kelsey's comment on the issue, the previous behavior was a bug, and MongoDB doesn't support this usecase for multikey indexes, so it should not have allowed the indexes to be created.

Thanks,
Mark

Comment by Phillip Wirth [ 17/Jan/18 ]

@Mark Agarunov I do not want to use it as text index, it is part of a compound index.

It is not mentioned in the changelogs either that this behavior has been changed!

Comment by Mark Agarunov [ 16/Jan/18 ]

Hello pwirth,

Thank you for the report. In the createIndex command in your example, the AllUnitIds field is not defined as a text index. To use this field as a text index, you would need to change AllUnitIds: 1 to AllUnitIds: "text" in the createIndex statement which should allow the field to contain arrays.

Thanks,
Mark

Comment by Phillip Wirth [ 16/Jan/18 ]

https://docs.mongodb.com/manual/core/index-text/index.html
states

MongoDB provides text indexes to support text search queries on string content. text indexes can include any field whose value is a string or an array of string elements.

Generated at Thu Feb 08 04:31:05 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.