I don't know if this is possible, searched docs but can't find an answer.
I have a scheme where users sign up with Facebook Id and it gives there full name and id.
Later on in the journey users can sign-up to the multiplayer part and choose a unique username defined as such:
//In >> var UserSchema = new mongoose.Schema
multiplayer.username: {type: String, unique: true, required: false}
My question is, when I attempted this with new user it just spits out the error:
New user request: Superman, facebookid: 13131231222
{ [MongoError: insertDocument :: caused by :: 11000 E11000 duplicate key error index: gameserver.users.$multiplayer.username_1 dup key: { : null }]
name: 'MongoError',
message: 'insertDocument :: caused by :: 11000 E11000 duplicate key error index: gameserver.users.$multiplayer.username_1 dup key: { : null }',
I've tried using default but it doesn't work, and I cannot use random because it's unique and not resettable.
Any ideas?
EDIT
I looked at http://stackoverflow.com/questions/7955040/mongodb-mongoose-unique-if-not-null
and it doesn't work, same error.