Last active
December 16, 2015 02:59
-
-
Save ilguzin/5366961 to your computer and use it in GitHub Desktop.
As comes from official mongo documentation you cannot create unique index on fields from embedded documents. Here is a workaround for those using $push to append values to array of embedded documents.
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
Mongo shell command | |
> db.users.update( | |
{ community:'Coomunity1', | |
'users.login': {'$ne': 'Login1'} | |
}, | |
{ $push: | |
{ users: {login:'Login1', pwd:'*****'} } | |
}, | |
{upsert: true}) | |
won't add new user into array of 'users' of a collection item as of condition "'users.login': {'$ne': 'Login1'}" is False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment