From 495eaa80933a10cb19c79fce5435eabb4be0dd67 Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 8 Apr 2009 14:01:48 -0400 Subject: [PATCH] empty field spec same as missing field spec for queries --- db/dbmessage.h | 2 ++ dbtests/querytests.cpp | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/db/dbmessage.h b/db/dbmessage.h index bdf48b5c25c..3420089af38 100644 --- a/db/dbmessage.h +++ b/db/dbmessage.h @@ -162,6 +162,8 @@ namespace mongo { if ( d.moreJSObjs() ) { fields = auto_ptr< set >(new set()); d.nextJsObj().getFieldNames(*fields); + if ( fields->size() == 0 ) + fields.reset(); } queryOptions = d.msg().data->dataAsInt(); } diff --git a/dbtests/querytests.cpp b/dbtests/querytests.cpp index 23d49a6b72a..1a2d3f75c29 100644 --- a/dbtests/querytests.cpp +++ b/dbtests/querytests.cpp @@ -349,6 +349,20 @@ namespace QueryTests { ASSERT( !error() ); } }; + + class EmptyFieldSpec : public ClientBase { + public: + ~EmptyFieldSpec() { + client().dropCollection( "querytests.EmptyFieldSpec" ); + } + void run() { + const char *ns = "querytests.EmptyFieldSpec"; + client().insert( ns, BSON( "a" << 1 ) ); + ASSERT( !client().findOne( ns, "" ).isEmpty() ); + BSONObj empty; + ASSERT( !client().findOne( ns, "", &empty ).isEmpty() ); + } + }; class All : public UnitTest::Suite { public: @@ -368,6 +382,7 @@ namespace QueryTests { add< OplogReplayMode >(); add< ArrayId >(); add< UnderscoreNs >(); + add< EmptyFieldSpec >(); } };