Fixed bug where presets don't get applied when there's overlapping field projection in mongodb query

This commit is contained in:
Zaid Abdulla committed 2013-07-29 23:40:20 +03:00
1 parent 0b596487a5
commit b61b746db4
2 files changed
+13

No files matched your search

+12
View File
@@ -71,6 +71,7 @@ testExpressions = (obj, expressions, lop) ->
else throw new Error('Unknown logical operator')
# generate field projection from a query
projection = (query, proj) ->
for k,v of query
if k.charAt(0) == '$' # this is a logical operator
@@ -79,6 +80,17 @@ projection = (query, proj) ->
else
proj[k] = 1
# optimize projection by removing overlaps
optimizeProjection = (obj) ->
keys = Object.keys(obj).sort()
for i in [1 ... keys.length]
a = keys[i-1]
b = keys[i]
if common.startsWith(b, a)
if b.charAt(a.length) == '.' or b.charAt(a.length - 1) == '.'
delete obj[b]
exports.test = test
exports.projection = projection
exports.optimizeProjection = optimizeProjection
+1
View File
@@ -84,6 +84,7 @@ exports.assertPresets = (deviceId, presetsHash, callback) ->
else
throw new Error('Unknown configuration type')
mongoQuery.optimizeProjection(projection)
db.devicesCollection.findOne({'_id' : deviceId}, projection, (err, device) ->
devicePresets = []
for p in presets