|
|
@@ -176,23 +176,35 @@ proto.getDependencies = function getDependencies(deps) {
|
|
|
* @returns {Object} JSONObj
|
|
|
**/
|
|
|
klass.depsToProjection = function depsToProjection(deps) {
|
|
|
- var bb = {};
|
|
|
+ var needId = false,
|
|
|
+ bb = {};
|
|
|
if (deps._id === undefined)
|
|
|
bb._id = 0;
|
|
|
|
|
|
var last = "";
|
|
|
Object.keys(deps).sort().forEach(function(it){
|
|
|
- if (last !== "" && it.slice(0, last.length) === last){
|
|
|
- // we are including a parent of *it so we don't need to
|
|
|
- // include this field explicitly. In fact, due to
|
|
|
- // SERVER-6527 if we included this field, the parent
|
|
|
- // wouldn't be fully included.
|
|
|
+ if (it.indexOf('_id') === 0 && (it.length === 3 || it[3] === '.')) {
|
|
|
+ needId = true;
|
|
|
return;
|
|
|
+ } else {
|
|
|
+ if (last !== "" && it.slice(0, last.length) === last){
|
|
|
+ // we are including a parent of *it so we don't need to
|
|
|
+ // include this field explicitly. In fact, due to
|
|
|
+ // SERVER-6527 if we included this field, the parent
|
|
|
+ // wouldn't be fully included.
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
last = it + ".";
|
|
|
bb[it] = 1;
|
|
|
});
|
|
|
|
|
|
+ if (needId) // we are explicit either way
|
|
|
+ bb._id = 1;
|
|
|
+ else
|
|
|
+ bb._id = 0;
|
|
|
+
|
|
|
+
|
|
|
return bb;
|
|
|
};
|
|
|
|
|
|
@@ -207,38 +219,6 @@ proto.serializeToArray = function serializeToArray(array, explain) {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-proto.depsToProjection = function depsToProjection(deps) {
|
|
|
- var needId = false,
|
|
|
- last,
|
|
|
- bb = {};
|
|
|
-
|
|
|
- for (var i = 0; i < deps.length; i++) {
|
|
|
- var it = deps[i];
|
|
|
- if (it.starsWith('_id') && (it.length === 3 || it[3] === '.')) {
|
|
|
- needId = true;
|
|
|
- continue;
|
|
|
- } else {
|
|
|
- if (!last && it.starsWith(last)) {
|
|
|
- // we are including a parent of *it so we don't need to include this field
|
|
|
- // explicitly. In fact, due to SERVER-6527 if we included this field, the parent
|
|
|
- // wouldn't be fully included. This logic relies on on set iterators going in
|
|
|
- // lexicographic order so that a string is always directly before of all fields it
|
|
|
- // prefixes.
|
|
|
- continue;
|
|
|
- }
|
|
|
- last = it + '.';
|
|
|
- bb[it] = 1;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (needId) // we are explicit either way
|
|
|
- bb._id = 1;
|
|
|
- else
|
|
|
- bb._id = 0;
|
|
|
-
|
|
|
- return JSON.stringy(bb);
|
|
|
-};
|
|
|
-
|
|
|
// Taken as a whole, these three functions should produce the same output document given the
|
|
|
// same deps set as mongo::Projection::transform would on the output of depsToProjection. The
|
|
|
// only exceptions are that we correctly handle the case where no fields are needed and we don't
|