Clear any overlap when using Mongo's $unset operator

This commit is contained in:
Zaid Abdulla committed 2016-08-16 13:12:27 -07:00
1 parent 5fd869c6b9
commit 12a6cd7d8b
1 file changed
+3
+3
View File
@@ -538,6 +538,9 @@ saveDevice = (deviceId, deviceData, isNew, callback) ->
return callback() if Object.keys(update).length == 0 return callback() if Object.keys(update).length == 0
if (update['$unset']?)
optimizeProjection(update['$unset'])
devicesCollection.update({'_id' : deviceId}, update, {upsert: isNew}, (err, result) -> devicesCollection.update({'_id' : deviceId}, update, {upsert: isNew}, (err, result) ->
if not err and result.result.n != 1 if not err and result.result.n != 1
return callback(new Error("Device #{deviceId} not found in database")) return callback(new Error("Device #{deviceId} not found in database"))