Enforcing unique values within a document

XMLWordPrintableJSON

    • Type: Question
    • Resolution: Duplicate
    • Priority: Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Should it be possible to enforce uniqueness of an object within an array within a single document using a unique index?

      For instance:

      db.foo.save( { a : [

      { b : 1 }

      ] } )
      db.foo.ensureIndex({_id: 1, 'a.b': 1},

      {unique: true}

      );

      // This succeeds. Should it fail?
      db.foo.update({}, { '$push' : { 'a':

      {b: 1}

      } });

            Assignee:
            Eliot Horowitz (Inactive)
            Reporter:
            Kyle Banker (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: