LearnBoost/mongoose — Issue #654: not allowed custom ObjectID?
Author: flockonus
Created: 2011-12-16 18:25:30+00:00
State: open

I'm having problem reading from a mongodb, with the following ObjectID: `battlefield-3` _(it is a existing DB)_

either:

```javascript
> m.Game.findById('battlefield-3', console.log );
{ stack: [Getter/Setter], arguments: undefined, type: undefined, message: 'Invalid ObjectId' }

> new mongoose.mongo.BSONPure.ObjectID('bf')
Error: Argument passed in must be a single String of 12 bytes or a string of 24 hex characters in hex format
```

But it is not invalid, since it is referenced on mongoDB docs:
http://www.mongodb.org/display/DOCS/Object+IDs
http://www.mongodb.org/display/DOCS/Optimizing+Object+IDs

I can read it using MongoID:

```ruby
ruby-1.8.7-p334 :006 > Game.find('battlefield-3')
# MONGODB bgr_dev['games'].find({:_id=>"battlefield-3"}).limit(-1).sort(_idasc)
=> #
```

Schemas
------

```
NODE.JS/MONGOOSE
var Schema = mongoose.Schema
, ObjectId = Schema.ObjectId;

var GameSchema = new Schema({
publisher : ObjectId
, name : {type: String, unique: true, set: function (v) { return v.toLowerCase() } }
, description : {type: String, set: function (v) { return v.replace(/\ String
field :published_date, :type => Date
field :platforms, :type => Array
field :genres, :type => Array
field :tags, :type => Array

key :name

validates_presence_of :name
validates_uniqueness_of :name, :case_sensitive => false

end
```