summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2010-11-15 16:43:04 -0500
committerEliot Horowitz <eliot@10gen.com>2010-11-15 16:43:04 -0500
commit8f0e8a2eb16b788ea805de1cc4299a6dc67075c4 (patch)
tree8f778cbe8b5fd2c31d20db958d225f0c0e841483
parent62878d24b7b99c13f914f8d992d38f246f0bbb57 (diff)
downloadmongo-8f0e8a2eb16b788ea805de1cc4299a6dc67075c4.tar.gz
Projection cleaning
-rw-r--r--db/projection.cpp19
-rw-r--r--db/projection.h19
-rw-r--r--db/scanandorder.h13
3 files changed, 27 insertions, 24 deletions
diff --git a/db/projection.cpp b/db/projection.cpp
index 55d9e20d0f5..519e3c5162f 100644
--- a/db/projection.cpp
+++ b/db/projection.cpp
@@ -17,6 +17,7 @@
#include "pch.h"
#include "projection.h"
+#include "../util/mongoutils/str.h"
namespace mongo {
@@ -114,12 +115,24 @@ namespace mongo {
fm->add(rest, skip, limit);
}
}
+
+ void Projection::transform( const BSONObj& in , BSONObjBuilder& b ) const {
+ BSONObjIterator i(in);
+ while ( i.more() ){
+ BSONElement e = i.next();
+ if ( mongoutils::str::equals( "_id" , e.fieldName() ) ){
+ if ( _includeID )
+ b.append( e );
+ }
+ else {
+ append( b , e );
+ }
+ }
+ }
BSONObj Projection::transform( const BSONObj& in ) const {
BSONObjBuilder b;
- BSONObjIterator i(in);
- while ( i.more() )
- append( b , i.next() );
+ transform( in , b );
return b.obj();
}
diff --git a/db/projection.h b/db/projection.h
index 5f15d20b2f3..b34c3be29cd 100644
--- a/db/projection.h
+++ b/db/projection.h
@@ -46,26 +46,27 @@ namespace mongo {
BSONObj getSpec() const { return _source; }
/**
- * appends e to b if user wants it
- * will descend into e if needed
- */
- void append( BSONObjBuilder& b , const BSONElement& e ) const;
-
-
- /**
* transforms in according to spec
* NOTE: this will stricy obey _id, which is not true
* for normal queries
*/
BSONObj transform( const BSONObj& in ) const;
+
/**
- * @return if _id should be returned
+ * transforms in according to spec
*/
- bool includeID() { return _includeID; }
+ void transform( const BSONObj& in , BSONObjBuilder& b ) const;
private:
+ /**
+ * appends e to b if user wants it
+ * will descend into e if needed
+ */
+ void append( BSONObjBuilder& b , const BSONElement& e ) const;
+
+
void add( const string& field, bool include );
void add( const string& field, int skip, int limit );
void appendArray( BSONObjBuilder& b , const BSONObj& a , bool nested=false) const;
diff --git a/db/scanandorder.h b/db/scanandorder.h
index a9de954e736..ee4af2e03d9 100644
--- a/db/scanandorder.h
+++ b/db/scanandorder.h
@@ -53,18 +53,7 @@ namespace mongo {
inline void fillQueryResultFromObj(BufBuilder& bb, Projection *filter, BSONObj& js, DiskLoc* loc=NULL) {
if ( filter ) {
BSONObjBuilder b( bb );
- BSONObjIterator i( js );
- while ( i.more() ){
- BSONElement e = i.next();
- const char * fname = e.fieldName();
-
- if ( strcmp( fname , "_id" ) == 0 ){
- if (filter->includeID())
- b.append( e );
- } else {
- filter->append( b , e );
- }
- }
+ filter->transform( js , b );
if (loc)
b.append("$diskLoc", loc->toBSONObj());
b.done();