Fix exception when adding and removing tags

Only happens if adding and removing tags within the same session.

Resolves: #229
This commit is contained in:
Zaid Abdulla committed 2017-04-21 15:05:08 -07:00
1 parent c58f93aeb2
commit ca2cce8ab6
1 file changed
+8
+8
View File
@@ -445,10 +445,18 @@ saveDevice = (deviceId, deviceData, isNew, callback) ->
if (update['$unset']?)
optimizeProjection(update['$unset'])
if update['$addToSet'] and update['$pull']
# Mongo doesn't allow $addToSet and $pull at the same time
update2 = {'$pull': update['$pull']}
delete update['$pull']
devicesCollection.update({'_id' : deviceId}, update, {upsert: isNew}, (err, result) ->
if not err and result.result.n != 1
return callback(new Error("Device #{deviceId} not found in database"))
if update2
return devicesCollection.update({'_id': deviceId}, update2, callback)
return callback(err)
)