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:
1 parent
c58f93aeb2
commit
ca2cce8ab6
1 file changed
+8
@@ -445,10 +445,18 @@ saveDevice = (deviceId, deviceData, isNew, callback) ->
|
|||||||
if (update['$unset']?)
|
if (update['$unset']?)
|
||||||
optimizeProjection(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) ->
|
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"))
|
||||||
|
|
||||||
|
if update2
|
||||||
|
return devicesCollection.update({'_id': deviceId}, update2, callback)
|
||||||
|
|
||||||
return callback(err)
|
return callback(err)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user