diff --git a/db/pdfile.cpp b/db/pdfile.cpp index 9cacfdfed44..fffa0bf74ff 100644 --- a/db/pdfile.cpp +++ b/db/pdfile.cpp @@ -1144,7 +1144,9 @@ assert( !eloc.isNull() ); Note that btree buckets which we insert aren't BSONObj's, but in that case god==true. */ BSONObj io((const char *) obuf); - if( !io.hasField("_id") && !addIndex && strstr(ns, ".local.") == 0 ) { + BSONElement idField = io.getField( "_id" ); + uassert( "_id cannot not be an array", idField.type() != Array ); + if( idField.eoo() && !addIndex && strstr(ns, ".local.") == 0 ) { addID = len; if ( writeId.eoo() ) { // Very likely we'll add this elt, so little harm in init'ing here. diff --git a/dbtests/querytests.cpp b/dbtests/querytests.cpp index 3602fd25697..bd95c45f286 100644 --- a/dbtests/querytests.cpp +++ b/dbtests/querytests.cpp @@ -322,6 +322,20 @@ namespace QueryTests { } }; + class ArrayId : public ClientBase { + public: + ~ArrayId() { + client().dropCollection( "querytests.ArrayId" ); + } + void run() { + const char *ns = "querytests.ArrayId"; + client().ensureIndex( ns, BSON( "_id" << 1 ) ); + ASSERT( !error() ); + client().insert( ns, fromjson( "{'_id':[1,2]}" ) ); + ASSERT( error() ); + } + }; + class All : public UnitTest::Suite { public: All() { @@ -338,6 +352,7 @@ namespace QueryTests { add< TailableDelete >(); add< TailableInsertDelete >(); add< OplogReplayMode >(); + add< ArrayId >(); } };