0

Is it possible to set what field should be the "id" field? I'm defining my scheme with:

var Person = app.ormDb.define('person', {
    id          : { type: String, index: true, default: function () { return uuid.v4(); } },
    oAuthID     : { type: String, index: true },
    name        : { type: String },
    gender      : { type: String },
    birth       : { type: Date },
    email       : { type: String },
    imageID     : { type: String },
    favorites   : { type: JSON, default: function() { return {cars : [], animals : []}; } },
    date        : { type: Date, default: function() { return new Date(); } },
    updated     : { type: Date, default: function() { return new Date(); } }
});

and my defined id field shows up in MongoDB but when I use jugglingdb to lookup a person the returned value for Person.id is the MongoDB _id ObjectId value. so my id is hidden.

Justin808
  • 20,859
  • 46
  • 160
  • 265

1 Answers1

0

_id is reserved in MongoDB as the primary key. This would explain why it can't be changed. You can place any value into this as long as it's unique. Hope that helps.

There is also currently an open issue in the jugglingdb-mongodb adapter. That addresses the reason why id is not returned. Basically if object.id exists when calling create it is removed before insert into the collection.