0

是否可以设置哪个字段应该是“id”字段?我正在定义我的方案:

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(); } }
});

并且我定义id的字段显示在 MongoDB 中,但是当我使用 jugglingdb 查找人员时, Person.id 的返回值是 MongoDB _id ObjectId 值。所以我id的被隐藏了。

4

1 回答 1

0

_id在 MongoDB 中保留为主键。这可以解释为什么它不能改变。只要它是唯一的,您就可以将任何值放入其中。希望有帮助。

jugglingdb-mongodb 适配器中目前还有一个未解决的问题。这解决了不返回 id 的原因。基本上,如果object.id在调用 create 时存在,则在插入集合之前将其删除。

于 2014-08-12T19:28:22.743 回答