Difference between php and python mongodb adapter
Question: I have code in php which reads example record from mongodb:

    
    
    <?php
    $client = new MongoClient("mongodb://localhost:27017");
    $db = $client->foo;
    $collection = $db->bar;
    $item = $collection->findOne();
    var_dump($item);
    

And similar code in python:

    
    
    import pymongo
    client = pymongo.MongoClient('localhost', 27017)
    db = client.foo
    collection = db.bar
    item = collection.find_one()
    print(item)
    

When I run php script i get expected result:

    
    
    array(11) {
      '_id' => class MongoBinData#6 (2) {
        public $bin => string(10) "somestring"
        public $type => int(3)
      }
      'a' => double(62051.444165621)
      'b' => int(974386)
      'c' => string(10) "some string"
      ... some int, float  and string fields ...
      'tags' => array(0) {}
    }
    

But, python script return error:

    
    
    Traceback (most recent call last):
      File "example.py", line 5, in <module>
        item = collection.find_one()
      File "/usr/local/lib/python2.7/dist-packages/pymongo/collection.py", line 724, in find_one
        for result in cursor.limit(-1):
      File "/usr/local/lib/python2.7/dist-packages/pymongo/cursor.py", line 1058, in next
        if len(self.__data) or self._refresh():
      File "/usr/local/lib/python2.7/dist-packages/pymongo/cursor.py", line 1002, in _refresh
        self.__uuid_subtype))
      File "/usr/local/lib/python2.7/dist-packages/pymongo/cursor.py", line 940, in __send_message
        self.__compile_re)
      File "/usr/local/lib/python2.7/dist-packages/pymongo/helpers.py", line 117, in _unpack_response
        compile_re)
    bson.errors.InvalidBSON: invalid length or type code
    

Why I can read data in php script and can't read data in python? Is it
possible to read this data in python?


Answer: Looks like you have stored some data in MongoDB that PyMongo considers
corrupt, but the PHP driver does not. If possible, please use "mongodump" to
dump only the offending document, or as few documents as possible, and attach
it to a new bug report. When you describe the problem, please tell us how you
**stored** the data: what driver version, what programming language, what code
you wrote to create the document. Register and click "Create Issue" at
<https://jira.mongodb.org/browse/PYTHON>

