Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-19361

Insert of document with duplicate _id fields should be forbidden

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Critical - P2 Critical - P2
    • 3.0.7, 3.1.9
    • Affects Version/s: None
    • Component/s: Write Ops
    • Minor Change
    • ALL
    • Hide

      Construct a BSON document with multiple _id fields and send it to the server.

      E.g. with MongoDB Perl driver v0.708.2.0:

      #!/usr/bin/env perl
      use v5.10;
      use strict;
      use warnings;
      use MongoDB;
      use Tie::IxHash;
      
      my $client = MongoDB::MongoClient->new;
      my $database = $client->get_database('test');
      my $collection = $database->get_collection('duptest');
      $collection->drop;
      
      $collection->insert( Tie::IxHash->new( _id => 1 ) );
      $collection->insert( [ _id => 2 ] );
      

      Then look at the test.duptest collection in the mongo shell.

      Show
      Construct a BSON document with multiple _id fields and send it to the server. E.g. with MongoDB Perl driver v0.708.2.0: #!/usr/bin/env perl use v5.10; use strict; use warnings; use MongoDB; use Tie::IxHash; my $client = MongoDB::MongoClient->new; my $database = $client->get_database('test'); my $collection = $database->get_collection('duptest'); $collection->drop; $collection->insert( Tie::IxHash->new( _id => 1 ) ); $collection->insert( [ _id => 2 ] ); Then look at the test.duptest collection in the mongo shell.
    • Quint 9 09/18/15

      (At behackett's suggestion, I'm opening this separate from SERVER-6439 to highlight the impact on _id, specifically.)

      A bug in the Perl driver revealed that it's possible to insert a document with duplicate/multiple _id fields.

      > db.duptest.find()
      { "_id" : NumberLong(1), "_id" : NumberLong(1) }
      { "_id" : NumberLong(2), "_id" : NumberLong(2) }
      

      I reproduced this against 3.1.5, 3.0.4, 2.6.10, and 2.4.14.

            Assignee:
            yunhe.wang YunHe Wang
            Reporter:
            david.golden@mongodb.com David Golden
            Votes:
            0 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved: