mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 03:55:55 +01:00
fix mongo functions so they return correct data if duplicate keys are passed. getObjects(['post:1', 'post:1'], callback) was only returning one object.
42 lines
790 B
JavaScript
42 lines
790 B
JavaScript
"use strict";
|
|
|
|
var helpers = {};
|
|
|
|
helpers.toMap = function(data) {
|
|
var map = {};
|
|
for (var i = 0; i<data.length; ++i) {
|
|
map[data[i]._key] = data[i];
|
|
}
|
|
return map;
|
|
}
|
|
|
|
helpers.fieldToString = function(field) {
|
|
if(field === null || field === undefined) {
|
|
return field;
|
|
}
|
|
|
|
if(typeof field !== 'string') {
|
|
field = field.toString();
|
|
}
|
|
// if there is a '.' in the field name it inserts subdocument in mongo, replace '.'s with \uff0E
|
|
field = field.replace(/\./g, '\uff0E');
|
|
return field;
|
|
};
|
|
|
|
helpers.valueToString = function(value) {
|
|
if(value === null || value === undefined) {
|
|
return value;
|
|
}
|
|
|
|
return value.toString();
|
|
};
|
|
|
|
helpers.done = function(cb) {
|
|
return function(err, result) {
|
|
if (typeof cb === 'function') {
|
|
cb(err, result);
|
|
}
|
|
};
|
|
};
|
|
|
|
module.exports = helpers; |