Browse Source

Refs #5122: Make serialize (explain) not crashy

Chris Sexton 12 years ago
parent
commit
27f68aceeb
1 changed files with 10 additions and 2 deletions
  1. 10 2
      lib/pipeline/documentSources/CursorDocumentSource.js

+ 10 - 2
lib/pipeline/documentSources/CursorDocumentSource.js

@@ -183,12 +183,20 @@ proto.setSource = function setSource(theSource) {
 
 
 proto.serialize = function serialize(explain) {
 proto.serialize = function serialize(explain) {
 	if (!explain)
 	if (!explain)
-		return this.value();
+		return null;
 
 
 	if (!this._cursorWithContext)
 	if (!this._cursorWithContext)
 		throw new Error("code 17135; Cursor deleted.");
 		throw new Error("code 17135; Cursor deleted.");
 
 
-	return this.value(); // big stuff here
+	// A stab at what mongo wants
+	return {
+		query: this._query,
+		sort: this._sort ? this._sort : null,
+		limit: this._limit ? this._limit : null,
+		fields: this._projection ? this._projection : null,
+		indexonly: false,
+		cursorType: this._cursorWithContext ? "cursor" : null
+	};
 };
 };
 
 
 // LimitDocumentSource has the setLimit function which trickles down to any documentsource
 // LimitDocumentSource has the setLimit function which trickles down to any documentsource