From 12a6cd7d8bf8559d91711c627db4365be8724334 Mon Sep 17 00:00:00 2001 From: Zaid Abdulla Date: Tue, 16 Aug 2016 13:12:27 -0700 Subject: [PATCH] Clear any overlap when using Mongo's $unset operator --- lib/db.coffee | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/db.coffee b/lib/db.coffee index a1841a7..f213484 100644 --- a/lib/db.coffee +++ b/lib/db.coffee @@ -538,6 +538,9 @@ saveDevice = (deviceId, deviceData, isNew, callback) -> return callback() if Object.keys(update).length == 0 + if (update['$unset']?) + optimizeProjection(update['$unset']) + 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"))