summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron <aaron@10gen.com>2009-04-07 11:02:29 -0400
committerAaron <aaron@10gen.com>2009-04-07 11:02:29 -0400
commit56f86969097441d91300a0328d7f7e4ffd80c375 (patch)
treef896b3fdb2a9c941c1555118353fa900cdca4c4f
parentf86715cb8516064ad17f8adede763c207fdde39a (diff)
downloadmongo-56f86969097441d91300a0328d7f7e4ffd80c375.tar.gz
don't allow _id to be an array
-rw-r--r--db/pdfile.cpp4
-rw-r--r--dbtests/querytests.cpp15
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 >();
}
};