ISSUE SUMMARY
An update to a text-indexed field may fail to update the text index. As a result a text search may not match the field contents, yielding incorrect search results.
For example, given a collection with a text index on field “title”:
> db.col.ensureIndex({title:"text"})
Inserting a document and searching for it produces the expected results:
> db.col.insert({title:"test"}) WriteResult({ "nInserted" : 1 }) > db.col.find({$text:{$search:"test"}}) { "_id" : ObjectId("53df95d559c54fcf80f8e418"), "title" : "test" }
But when the text-indexed field is modified under the conditions outlined above, queries may return incorrect results:
> db.col.update({title:"test"}, {$set:{title:"fail"}}) WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 }) > db.col.find({$text:{$search:"test"}}) { "_id" : ObjectId("53df95d559c54fcf80f8e418"), "title" : "fail" }
At this stage, if the document grows sufficiently and needs to be moved, the data in the index entry no longer points to a valid document, and queries that hit the index return an error:
> db.col.update({}, {$set : { padding : new Array(512).join('x') }}) WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 }) > db.col.find({$text:{$search:"test"}}) error: { "$err" : "BSONObj size: -286331154 (0xEEEEEEEE) is invalid. Size must be between 0 and 16793600(16MB) First element: _id: ObjectId('53dfae9755c5ce157d6a8560')", "code" : 10334 }
USER IMPACT
Users who update documents in a collection that contains a text index may see incorrect/incomplete search results.
Specifically, an update may cause corrupt index entries if all of the following conditions are met:
- the update modifies a text-indexed field, and
- the update does not change the size of any text-indexed values, and
- the update is in-place (does not result in a document move), and
- the update does not modify another index
None of the following operations trigger this bug:
- an update that changes the size of a text-indexed value
- an update that results in a document move
- an update that modifies another index
- an update that replaces the entire document
- an insert, query, or delete operation
WORKAROUNDS
No workarounds exist for this issue. To fix this issue, users must upgrade to 2.4.11 or 2.6.4 and then rebuild text indexes, either by dropping and creating each index, or by resyncing a new replica set member.
There is no simple way to identify whether or not a text index is affected by this issue. If any updates have been issued to documents in a collection with a text index, the index may have been impacted.
AFFECTED VERSIONS
MongoDB versions 2.4.0 through 2.4.10, and 2.6.0 through 2.6.3 are affected by this issue.
FIX VERSION
The fix is included in the 2.4.11 and 2.6.4 production releases.
RESOLUTION DETAILS
Correctly determine if update with text index is in-place.
Original description
- is duplicated by
-
SERVER-13651 "btree: key+recloc already in index" error when updating text index
- Closed
- related to
-
SERVER-14829 UpdateIndexData::clear() should reset all member variables
- Closed
- links to