Created
March 13, 2014 12:31
-
-
Save kaworu/9527549 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MongoDB shell version: 2.4.8 | |
connecting to: dev | |
> db.some_collection.ensureIndex({"sub.id":1}, {unique:true}); | |
> db.some_collection.insert({sub:[{id:42}]}) | |
> db.some_collection.find() | |
{ "_id" : ObjectId("5321a4b172a13ee462bc5c20"), "sub" : [ { "id" : 42 } ] } | |
> db.some_collection.update({}, {$push: {sub: {id:42}}}) | |
> db.some_collection.find() | |
{ "_id" : ObjectId("5321a4b172a13ee462bc5c20"), "sub" : [ { "id" : 42 }, { "id" : 42 } ] } | |
> db.some_collection.insert({sub:[{id:42}]}) | |
E11000 duplicate key error index: dev.some_collection.$sub.id_1 dup key: { : 42.0 } | |
> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment