Bläddra i källkod

Refs #5126: Rearrange file

Chris Sexton 11 år sedan
förälder
incheckning
81902e8d61
1 ändrade filer med 31 tillägg och 46 borttagningar
  1. 31 46
      lib/pipeline/documentSources/MatchDocumentSource.js

+ 31 - 46
lib/pipeline/documentSources/MatchDocumentSource.js

@@ -30,52 +30,6 @@ proto.getSourceName = function getSourceName(){
 	return klass.matchName;
 };
 
-/**
- * Create a JSONObj suitable for Matcher construction.
- *
- * This is used after filter analysis has moved as many filters to
- * as early a point as possible in the document processing pipeline.
- * See db/Matcher.h and the associated wiki documentation for the
- * format.  This conversion is used to move back to the low-level
- * find() Cursor mechanism.
- *
- * @param builder the builder to write to
- *
- *
- * TO REMOVE
- **/
-proto.toMatcherJson = function toMatcherJson(builder) {
-	var q = this.matcher._pattern;
-	for(var k in q){
-		builder[k] = q[k];
-	}
-};
-
-klass.uassertNoDisallowedClauses = function uassertNoDisallowedClauses(query) {
-	for(var key in query){
-		if(query.hasOwnProperty(key)){
-			// can't use the Matcher API because this would segfault the constructor
-			if (query[key] == "$where") throw new Error("code 16395; $where is not allowed inside of a $match aggregation expression");
-			// geo breaks if it is not the first portion of the pipeline
-			if (query[key] == "$near") throw new Error("code 16424; $near is not allowed inside of a $match aggregation expression");
-			if (query[key] == "$within") throw new Error("code 16425; $within is not allowed inside of a $match aggregation expression");
-			if (query[key] == "$nearSphere") throw new Error("code 16426; $nearSphere is not allowed inside of a $match aggregation expression");
-			if (query[key] instanceof Object && query[key].constructor === Object) this.uassertNoDisallowedClauses(query[key]);
-		}
-	}
-};
-
-klass.createFromJson = function createFromJson(jsonElement, ctx) {
-	if (!(jsonElement instanceof Object) || jsonElement.constructor !== Object) throw new Error("code 15959 ; the match filter must be an expression in an object");
-	klass.uassertNoDisallowedClauses(jsonElement);
-	var matcher = new MatchDocumentSource(jsonElement, ctx);
-	return matcher;
-};
-
-//
-// TODO:RE-ORDER THIS FILE
-//
-
 proto.getNext = function getNext(callback) {
 	var self = this,
 		next;
@@ -116,10 +70,41 @@ proto.serialize = function(explain) {
 	return out;
 };
 
+klass.uassertNoDisallowedClauses = function uassertNoDisallowedClauses(query) {
+	for(var key in query){
+		if(query.hasOwnProperty(key)){
+			// can't use the Matcher API because this would segfault the constructor
+			if (query[key] == "$where") throw new Error("code 16395; $where is not allowed inside of a $match aggregation expression");
+			// geo breaks if it is not the first portion of the pipeline
+			if (query[key] == "$near") throw new Error("code 16424; $near is not allowed inside of a $match aggregation expression");
+			if (query[key] == "$within") throw new Error("code 16425; $within is not allowed inside of a $match aggregation expression");
+			if (query[key] == "$nearSphere") throw new Error("code 16426; $nearSphere is not allowed inside of a $match aggregation expression");
+			if (query[key] instanceof Object && query[key].constructor === Object) this.uassertNoDisallowedClauses(query[key]);
+		}
+	}
+};
+
+klass.createFromJson = function createFromJson(jsonElement, ctx) {
+	if (!(jsonElement instanceof Object) || jsonElement.constructor !== Object) throw new Error("code 15959 ; the match filter must be an expression in an object");
+	klass.uassertNoDisallowedClauses(jsonElement);
+	var matcher = new MatchDocumentSource(jsonElement, ctx);
+	return matcher;
+};
+
 proto.getQuery = function getQuery() {
 	return this.matcher._pattern;
 };
 
+/** Returns the portion of the match that can safely be promoted to before a $redact.
+ *  If this returns an empty BSONObj, no part of this match may safely be promoted.
+ *
+ *  To be safe to promote, removing a field from a document to be matched must not cause
+ *  that document to be accepted when it would otherwise be rejected. As an example,
+ *  {name: {$ne: "bob smith"}} accepts documents without a name field, which means that
+ *  running this filter before a redact that would remove the name field would leak
+ *  information. On the other hand, {age: {$gt:5}} is ok because it doesn't accept documents
+ *  that have had their age field removed.
+ */
 proto.redactSafePortion = function redactSafePortion() {
 	throw new Error("not implemented");
 };