Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-14738

Updates to documents with text-indexed fields may lead to incorrect entries

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical - P2
    • Resolution: Fixed
    • Affects Version/s: 2.4.10, 2.6.1, 2.7.4
    • Fix Version/s: 2.4.11, 2.6.4, 2.7.5
    • Component/s: Text Search
    • Labels:
      None
    • Operating System:
      ALL
    • Backport Completed:
    • Steps To Reproduce:
      Hide

      db.search.drop()
      db.search.insert({ title: 'Power', language: 'fr' })
      db.search.ensureIndex({ title: 'text' })
       
      db.search.find({ $text: { $search: 'Power' } })
      // Nothing... 
       
      // When stemmed Power become 'pow'
      db.search.find({ $text: { $search: 'pow' } })
      // { "_id" : ObjectId("53da06bc72556e0e2e08d614"), "title" : "Power", "language" : "fr" }
       
      // So i changed the language field to the correct one (en)
      var id = db.search.findOne()._id
      db.search.update({ _id: id }, { $set: { language: "en" } })
       
      db.search.find({ $text: { $search: 'Power' } })
      // Nothing again... (Reindexation is not triggered)
       
      db.search.update({ _id: id }, { $set: { title: "Power " } })
      db.search.find({ $text: { $search: 'Power' } })
      // I finally find my documment (an update of the indexed field trigger the reindexation with the good language)
       

      Show
      db.search.drop() db.search.insert({ title: 'Power', language: 'fr' }) db.search.ensureIndex({ title: 'text' })   db.search.find({ $text: { $search: 'Power' } }) // Nothing...   // When stemmed Power become 'pow' db.search.find({ $text: { $search: 'pow' } }) // { "_id" : ObjectId("53da06bc72556e0e2e08d614"), "title" : "Power", "language" : "fr" }   // So i changed the language field to the correct one (en) var id = db.search.findOne()._id db.search.update({ _id: id }, { $set: { language: "en" } })   db.search.find({ $text: { $search: 'Power' } }) // Nothing again... (Reindexation is not triggered)   db.search.update({ _id: id }, { $set: { title: "Power " } }) db.search.find({ $text: { $search: 'Power' } }) // I finally find my documment (an update of the indexed field trigger the reindexation with the good language)  

      Description

      Issue Status as of Aug 04, 2014

      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

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                17 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: