【发布时间】:2017-03-24 15:43:40
【问题描述】:
我正在尝试 SailsJS (v1.0.0-32) 的 beta 版本,但在配置自定义 ID 时遇到了一些问题。您将在下面找到我当前的配置:
modelExample.js
module.exports = {
attributes: {
id:{
type: 'string',
columnName: '_id'
},
attr: {
type: 'number'
}
}
}
模型配置config/models.js
attributes: {
createdAt: { type: 'number', autoCreatedAt: true, },
updatedAt: { type: 'number', autoUpdatedAt: true, },
id: { type: 'string', columnName: '_id' },
}
试图插入的元素:
{id:"600000", attr:40}
error 在尝试创建一条记录时,我在尝试创建的元素中包含属性“id”:
AdapterError: Unexpected error from database adapter: Invalid primary key value provided for `id`. Cannot interpret `600000` as a Mongo id.
(Usually, this is the result of a bug in application logic.)
似乎 mongo 不喜欢字符串 600000 作为 id,但我不确定我是否误解了与 mongo 中的 id 相关的内容。在旧版本的风帆中,我从来没有遇到过这个问题,因为 id 覆盖很简单。
更多信息,sails-mongo 适配器版本为:"sails-mongo": "^1.0.0-5"
【问题讨论】:
标签: sails.js sails-mongo