Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

handle empty objects better in FieldMatcher SERVER-224

  • Loading branch information...
commit 9d23766511b28a52381fd039e890e62eaf1807a2 1 parent 79fcbfa
@erh erh authored
Showing with 21 additions and 3 deletions.
  1. +9 −3 db/queryutil.cpp
  2. +12 −0 jstests/fm1.js
View
12 db/queryutil.cpp
@@ -250,8 +250,12 @@ namespace mongo {
BSONObj FieldMatcher::extractDotted( const string& path , const BSONObj& o ) const {
string::size_type i = path.find( "." );
- if ( i == string::npos )
- return o.getField( path.c_str() ).wrap();
+ if ( i == string::npos ){
+ const BSONElement & e = o.getField( path.c_str() );
+ if ( e.eoo() )
+ return BSONObj();
+ return e.wrap();
+ }
string left = path.substr( 0 , i );
BSONElement e = o[left];
@@ -269,7 +273,9 @@ namespace mongo {
void FieldMatcher::append( BSONObjBuilder& b , const BSONElement& e ) const {
string next = fields.find( e.fieldName() )->second;
- if ( next.size() == 0 || next == "." || e.type() != Object ){
+ if ( e.eoo() ){
+ }
+ else if ( next.size() == 0 || next == "." || e.type() != Object ){
b.append( e );
}
else {
View
12 jstests/fm1.js
@@ -0,0 +1,12 @@
+
+t = db.fm1;
+t.drop();
+
+t.insert({foo:{bar:1}})
+t.find({},{foo:1}).toArray();
+t.find({},{'foo.bar':1}).toArray();
+t.find({},{'baz':1}).toArray();
+t.find({},{'baz.qux':1}).toArray();
+t.find({},{'foo.qux':1}).toArray();
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.