Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-2151

Comment on: "manual/core/index-sparse.txt"

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • 01112017-cleanup
    • None
    • None

    Description

      Your example of the unique sparse index is wrong. Why shouldn't one be able to insert the last two records? Unique index is on score and not on userid!
      Here my console output to prove it:
      mongos> db.scores.find()
      mongos> db.scores.ensureIndex(

      { score: 1 }

      ,

      { sparse: true, unique: true }

      )
      mongos> db.scores.insert(

      { "userid": "PWWfO8lFs1", "score": "43" }

      )
      mongos> db.scores.insert(

      { "userid": "XlSOX66gEy", "score": "34" }

      )
      mongos> db.scores.insert(

      { "userid": "nuZHu2tcRm" }

      )
      mongos> db.scores.insert(

      { "userid": "HIGvEZfdc5" }

      )
      mongos> db.scores.find()

      { "_id" : ObjectId("526a8be3f46d2610cd367984"), "userid" : "PWWfO8lFs1", "score" : "43" } { "_id" : ObjectId("526a8be3f46d2610cd367985"), "userid" : "XlSOX66gEy", "score" : "34" } { "_id" : ObjectId("526a8be3f46d2610cd367986"), "userid" : "nuZHu2tcRm" } { "_id" : ObjectId("526a8be5f46d2610cd367987"), "userid" : "HIGvEZfdc5" }

      mongos> db.scores.insert(

      { "userid": "PWWfO8lFs1", "score": "82" }

      )
      mongos> db.scores.insert(

      { "userid": "XlSOX66gEy", "score": "90" }

      )
      mongos> db.scores.find()

      { "_id" : ObjectId("526a8be3f46d2610cd367984"), "userid" : "PWWfO8lFs1", "score" : "43" } { "_id" : ObjectId("526a8be3f46d2610cd367985"), "userid" : "XlSOX66gEy", "score" : "34" } { "_id" : ObjectId("526a8be3f46d2610cd367986"), "userid" : "nuZHu2tcRm" } { "_id" : ObjectId("526a8be5f46d2610cd367987"), "userid" : "HIGvEZfdc5" } { "_id" : ObjectId("526a8bf5f46d2610cd367988"), "userid" : "PWWfO8lFs1", "score" : "82" } { "_id" : ObjectId("526a8bf7f46d2610cd367989"), "userid" : "XlSOX66gEy", "score" : "90" }

      mongos>

      Attachments

        Activity

          People

            kay.kim@mongodb.com Kay Kim (Inactive)
            kay.agahd@idealo.de Kay Agahd
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              10 years, 16 weeks, 5 days ago