From a22e638e9aa8c7f7bf85b53fe9860b5b27a947b4 Mon Sep 17 00:00:00 2001 From: Zaid Abdulla Date: Wed, 16 Oct 2013 18:40:28 +0300 Subject: [PATCH] Fixed bug in query projection --- mongo-query.coffee | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mongo-query.coffee b/mongo-query.coffee index 57b5ec2..61b67d0 100644 --- a/mongo-query.coffee +++ b/mongo-query.coffee @@ -84,12 +84,15 @@ projection = (query, proj) -> optimizeProjection = (obj) -> keys = Object.keys(obj).sort() return if keys.length <= 1 - for i in [1 ... keys.length] + i = 1 + while i < 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] + keys.splice(i--, 1) + ++ i exports.test = test