【发布时间】:2020-06-07 02:14:16
【问题描述】:
我的sails 应用程序在连接到mysql 数据库时运行良好。然而,我需要切换到 mongoDB,因为它是项目的要求,这就是我面临的问题。
我的模型与其工作有一些关系,为了实现这一点,我必须进行一些修改,其中包括:我使用uuid 为每个模型设置主键 (id)(id 是自动生成的由 mysql 之前)。但是,当我尝试向服务器提交请求时,我遇到了错误:
AdapterError: Unexpected error from database adapter: Invalid primary key value provided for `id`. Cannot interpret `9456b206-ebcf-4a6d-b81c-93964c027f04` as a Mongo id.
(Usually, this is the result of a bug in application logic.)
这是我的一个模型的示例 -pick.js:
module.exports = {
attributes: {
userId: {
type: 'string',
required: true,
//unique: true,
},
comment:{
type: 'string',
required: true
},
createdBy:{
type: 'string',
required: true
},
info: {
model: 'personalinfo'
},
admin: {
model: 'admin'
},
id:{
type: 'string',
},
},
};
【问题讨论】:
-
听起来你在尝试使用空字符串作为 id,这是不允许的。
-
不,我没有使用空字符串,如果您检查我的问题的正文,您会看到我尝试添加的字符串。我也更新了我的问题
-
你当时使用的 id 值是多少?
-
stackoverflow.com/questions/43003762/… 看起来是正确的答案。