marcello3d/node-mongolian — Issue #71: Can't find records when searching by the _id as a string
Author: CrankyDragon
Created: 2012-01-04 04:36:01+00:00
State: open

Here's a quick code sample:

```
var Mongolian = require('mongolian')
, db = new Mongolian('mongo://localhost/modelr_db', {log:false})
, collection = db.collection('test_collection')

collection.insert({
_id : '4f03ce14000000df01000002',
hello : 'World',
})

collection.findOne(function(err, doc_1) {
var id = doc_1._id.toString();
var query = { _id: new Mongolian.ObjectId(id) }

// This don't work
console.log(doc_1)
collection.findOne(query, function(err, doc_2) {
console.log(doc_2)
})

/// But this works
query = { _id: doc_1._id}
collection.findOne(query, function(err, doc_3) {
console.log(doc_3)
})

})
```

And the output:

console.log(doc_1) -> { _id: '4f03ce14000000df01000002', hello: 'World' }
console.log(doc_2) -> undefined
console.log(doc_3) -> { _id: '4f03ce14000000df01000002', hello: 'World' }

Why does the query fail when using a string made into an ObjectId?