|
|
@@ -218,75 +218,3 @@ proto.serializeToArray = function serializeToArray(array, explain) {
|
|
|
array.push(entry);
|
|
|
}
|
|
|
};
|
|
|
-
|
|
|
-// 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
|
|
|
-// need to work around the above mentioned bug with subfields of _id (SERVER-7502). This is
|
|
|
-// tested in a DEV block in DocumentSourceCursor::findNext().
|
|
|
-//
|
|
|
-// Output from this function is input for the next two
|
|
|
-//
|
|
|
-// ParsedDeps is a simple recursive look-up table. For each field in a ParsedDeps:
|
|
|
-// If the value has type==Bool, the whole field is needed
|
|
|
-// If the value has type==Object, the fields in the subobject are needed
|
|
|
-// All other fields should be missing which means not needed
|
|
|
-// DocumentSource::ParsedDeps DocumentSource::parseDeps(const set<string>& deps) {
|
|
|
-// MutableDocument md;
|
|
|
-klass.parseDeps = function parseDeps(deps) {
|
|
|
- var doc,
|
|
|
- last;
|
|
|
-
|
|
|
- for (var i = 0; i < deps.length; i++) {
|
|
|
- var it = deps[i];
|
|
|
- if (!last && it.startsWith(last)) {
|
|
|
- // we are including a parent of *it so we don't need to include this field
|
|
|
- // explicitly. In fact, 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 + '.';
|
|
|
- Object.setAtPath(doc, it, true);
|
|
|
- }
|
|
|
-
|
|
|
- return doc;
|
|
|
-};
|
|
|
-
|
|
|
-klass.documentFromJsonWithDeps = function documentFromJsonWithDeps(obj, deps) {
|
|
|
- var doc = {},
|
|
|
- self = this;
|
|
|
-
|
|
|
- var arrayHelper = function(field, isNeeded) {
|
|
|
- return field.map(function(f) {
|
|
|
- DocumentSource.documentFromJsonWithDeps(f, isNeeded);
|
|
|
- });
|
|
|
- };
|
|
|
-
|
|
|
- for (var i = 0; i < obj.keys().length; i++) {
|
|
|
- var fieldName = obj.keys()[i],
|
|
|
- field = obj[fieldName],
|
|
|
- isNeeded = deps[fieldName];
|
|
|
-
|
|
|
- if (!isNeeded)
|
|
|
- continue;
|
|
|
-
|
|
|
- if (typeof isNeeded === Boolean) {
|
|
|
- Object.setAtPath(doc, fieldName, field);
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- if (!(isNeeded instanceof Object))
|
|
|
- throw new Error("dependencies missing for object");
|
|
|
-
|
|
|
- if (field instanceof Array)
|
|
|
- Object.setAtPath(doc, fieldName, arrayHelper(field, isNeeded));
|
|
|
-
|
|
|
- if (field instanceof Object) { // everything is...
|
|
|
- var sub = DocumentSource.documentFromJsonWithDeps(field, isNeeded);
|
|
|
- Object.setAtPath(doc, fieldName, sub);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return doc;
|
|
|
-};
|