[SERVER-7070] Insertion of document with duplicate fields permitted in C++ Created: 19/Sep/12  Updated: 10/Jul/15  Resolved: 19/Sep/12

Status: Closed
Project: Core Server
Component/s: Internal Client
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: J Rassi Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-6439 Duplicate fields at the same level sh... Backlog
Operating System: ALL
Participants:

 Description   

Using the C++ driver, nothing prevents a user from inserting a document that has two fields which share a name. I don't believe that the behavior of future updates on this document is documented or well-defined (as a sidenote, operating on this document can't crash the server, right?).

See:

> db.test.find()
{ "_id" : ObjectId("5058f25f7d54ac9bc09d4e57"), "a" : 0, "a" : 0 }
>

as a product of:

#include "mongo/client/dbclient.h"
using namespace mongo;
int main() {
  DBClientConnection c;
  c.connect("localhost");
  BSONObj bsonData = BSON("a" << 0 << "a" << 0);
  c.insert("test.test", bsonData);
  return 0;
}



 Comments   
Comment by Scott Hernandez (Inactive) [ 19/Sep/12 ]

This is a not a bug as bson doesn't exclude duplication of the fields with the same name at the same level. There may be places where this is still used in the server code, like it used to be used in the oplog.

If anything the server should be made to disable this during/in objCheck mode (and if we ever make that the default), but this should not be disallowed when generating bson (unless we change the bson spec).

Generated at Thu Feb 08 03:13:33 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.