I was trying to delete a specific value (a game) from my array in my schema, and this is the code:
User.update({ userName: user }, { $pull: { games: { _id: deleteItem } } }, function (err, val) {
console.log(err);
});
the schema:
const userSchema = new mongoose.Schema({
userName: { type: String, index: true, unique: true },
userPassword: String,
games: [gameSchema]
});
the error:
MongoError: E11000 duplicate key error collection: mountain.users index: games.password_1 errmsg: 'E11000 duplicate key error collection: mountain.users index: games.password_1 dup key: { games.password: null }', [Symbol(mongoErrorContextSymbol)]: {} }
why is the error apear and how can I solve it?/other way to delete a value from array inside on object
thanks for your help!
db.collection.getIndexes()
output. – prasad_games.password
does not exist. You can consider deleting the index:user.games.password
. – noam$pull
the password away from it. – noam