diff options
author | Aaron <aaron@10gen.com> | 2009-04-07 11:02:29 -0400 |
---|---|---|
committer | Aaron <aaron@10gen.com> | 2009-04-07 11:02:29 -0400 |
commit | 56f86969097441d91300a0328d7f7e4ffd80c375 (patch) | |
tree | f896b3fdb2a9c941c1555118353fa900cdca4c4f | |
parent | f86715cb8516064ad17f8adede763c207fdde39a (diff) | |
download | mongo-56f86969097441d91300a0328d7f7e4ffd80c375.tar.gz |
don't allow _id to be an array
-rw-r--r-- | db/pdfile.cpp | 4 | ||||
-rw-r--r-- | dbtests/querytests.cpp | 15 |
2 files changed, 18 insertions, 1 deletions
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 >(); } }; |