duplicate value on unique index error (#4560)

This commit is contained in:
Diamond Lewis
2018-02-09 07:39:35 -06:00
committed by GitHub
parent c16e6bb5e0
commit 3cd77eeb7c
2 changed files with 31 additions and 1 deletions

View File

@@ -421,7 +421,13 @@ export class MongoStorageAdapter implements StorageAdapter {
const mongoWhere = transformWhere(className, query, schema);
return this._adaptiveCollection(className)
.then(collection => collection._mongoCollection.findAndModify(mongoWhere, [], mongoUpdate, { new: true }))
.then(result => mongoObjectToParseObject(className, result.value, schema));
.then(result => mongoObjectToParseObject(className, result.value, schema))
.catch(error => {
if (error.code === 11000) {
throw new Parse.Error(Parse.Error.DUPLICATE_VALUE, 'A duplicate value for a field with unique values was provided');
}
throw error;
});
}
// Hopefully we can get rid of this. It's only used for config and hooks.