final fix for #1884

fix mongo functions so they return correct data if duplicate keys are
passed. getObjects(['post:1', 'post:1'], callback) was only returning
one object.
This commit is contained in:
barisusakli
2014-07-24 12:41:22 -04:00
parent 3557aa2f9a
commit 8dce99250b
3 changed files with 14 additions and 23 deletions

View File

@@ -2,23 +2,13 @@
var helpers = {};
helpers.findItem = function(data, key) {
if(!data) {
return null;
helpers.toMap = function(data) {
var map = {};
for (var i = 0; i<data.length; ++i) {
map[data[i]._key] = data[i];
}
for(var i=0; i<data.length; ++i) {
if(data[i]._key === key) {
var item = data.splice(i, 1);
if(item && item.length) {
return item[0];
} else {
return null;
}
}
}
return null;
};
return map;
}
helpers.fieldToString = function(field) {
if(field === null || field === undefined) {