我正在使用:
当我获得mongodb集合的文档时,出现如下错误:
In model `archive`: debug: The default primary key attribute (`id`) is not set up correctly. debug: When using `sails-mongo`, primary keys MUST have `columnName: '_id'`, debug: and must _not_ have `autoIncrement: true`. debug: Also, in most cases (unless `dontUseObjectIds` has been set to `true` for the model), debug: then the `type` of the primary key must also be `string`.
sails.config.datastores.js
module.exports.datastores = {
default: {
adapter: 'sails-mongo',
host: 'localhost',
port: 27017,
database: 'test',
}
};
sails.config.models.js
module.exports.models = {
migrate: 'safe',
attributes: {
createdAt: { type: 'number', autoCreatedAt: true, },
updatedAt: { type: 'number', autoUpdatedAt: true, },
id: { type: 'string', columnName: '_id' },
},
dataEncryptionKeys: {
default: 'RWcFGJN8+at5E7eIwNCIQxkR7P0nRAW8Fg4c9tzwFTw='
},
cascadeOnDestroy: true
};
api.models.User.js
module.exports = {
tableName: 'user',
attributes: {
name: {
type: 'string'
},
age: {
type: 'number',
}
},
};
运行 api.controllers.UserController.js
时出现错误module.exports = {
getUsers: function (req, res) {
let users = User.find();
return res.send(users);
},
};