Jelajahi Sumber

Refs #5129: Wake coalesce pass

Chris Sexton 12 tahun lalu
induk
melakukan
332582a586
1 mengubah file dengan 7 tambahan dan 4 penghapusan
  1. 7 4
      lib/pipeline/documentSources/SortDocumentSource.js

+ 7 - 4
lib/pipeline/documentSources/SortDocumentSource.js

@@ -24,7 +24,6 @@ var SortDocumentSource = module.exports = function SortDocumentSource(ctx){
 	* on the first call to any method on this source.  The populated
 	* boolean indicates that this has been done
 	**/
-	// TODO clean these up
 	this.populated = false;
 	this.docIterator = null; // a number tracking our position in the documents array
 	this.documents = []; // an array of documents
@@ -70,8 +69,10 @@ proto.getDependencies = function getDependencies(deps) {
 
 proto.coalesce = function coalesce(nextSource) {
 	if (!this.limitSrc) {
-		if (nextSource instanceof LimitDocumentSource)
+		if (nextSource instanceof LimitDocumentSource) {
+			this.limitSrc = nextSource;
 			return nextSource;
+		}
 		return false;
 	} else {
 		return this.limitSrc.coalesce(nextSource);
@@ -108,7 +109,7 @@ proto.serializeToArray = function serializeToArray(array, explain) {
 	if (explain) {
 		doc.sortKey = this.serializeSortKey();
 		doc.mergePresorted = this._mergePresorted;
-		doc.limit = this.limitSrc ? this.limitSrc.getLimit() : null;
+		doc.limit = this.limitSrc ? this.limitSrc.getLimit() : undefined;
 		array.push(doc);
 	} else {
 		var inner = this.serializeSortKey();
@@ -141,7 +142,7 @@ proto.addKey = function addKey(fieldPath, ascending) {
 	if (ascending === true || ascending === false) {
 		this.vAscending.push(ascending);
 	} else {
-		// TODO: This doesn't appear to be an error?
+		// This doesn't appear to be an error in real mongo?
 		throw new Error("ascending must be true or false");
 	}
 };
@@ -263,3 +264,5 @@ klass.createFromJson = function createFromJson(jsonElement, ctx) {
 	if (sortKeys <= 0) throw new Error("code 15976; " + klass.sortName + " must have at least one sort key");
 	return nextSort;
 };
+
+// makeSortOptions