KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
The mongo documentation states that "When a document is saved to a collection with unique indexes, any missing indexed keys will be inserted with null values. Thus, it won't be possible to insert multiple documents missing the same indexed key." So is it impossible to create a unique index on an optional field? Should I create a compound index with say a userId as well to solve this? In my specific case I have a user collection that has an optional embedded oauth object. e.g. >db.users.ensureIndex( { "name":1, "oauthConnections.provider" : 1, "oauthConnections.providerId" : 1 } ); My sample user { name: "Bob" ,pwd: "myPwd" ,oauthConnections [ { "provider":"Facebook", "providerId" : "12345", "key":"blah" } ,{ "provider":"Twitter", "providerId" : "67890", "key":"foo" } ] }
Tags (comma-separated)
Save Edits
Cancel