scottwrobinson / camo

A class-based ES6 ODM for Mongo-like databases.
556 stars 80 forks source link

Allow custom _id #29

Closed dcsan closed 8 years ago

dcsan commented 8 years ago

I'm using meteorJS which does some odd things with the _id field for mongo records. I want to use plain strings as _id s with Camo to avoid this type of mix/match when writing from a raw node app with camo:

image

I tried overriding the _id field in a document, but that didn't work. Is this something that can be done?


var Document = require('camo').Document;

class Lessons extends Document {
  constructor() {
    super('Lessons');
    this._id = 'id' + Math.random;
    this.cname = String;
    this.rive = String;
  }

  static collectionName() {
    return 'Lessons';
  }

}

info: http://stackoverflow.com/questions/15318184/meteor-collection-objectid-vs-mongodb-objectid

scottwrobinson commented 8 years ago

As of right now Camo does not allow you to provide your own custom _id. Looks like both Mongo and NeDB support this, so I'll add it to Camo as well. Just make sure you conform to the id requirements of whichever database you're using (unique, 16 or 24 characters long, etc).

Thanks!