无法使用 MongoDB 配置 Keystone 6
Unable to configure Keystone 6 with MongoDB
我正在尝试使用 MongoDB 作为数据库来设置 Keystone。在 运行 keystone-next
时,命令出错并显示以下错误消息:Error: Invalid db configuration. Please specify db.provider as either "sqlite" or "postgresql" at getDBProvider
.
他们的文档没有明确说明要将哪些值作为 db.provider
传递以使用 MongoDB 作为数据库。
以下是keystone.ts
的内容:
import { config, createSchema } from '@keystone-next/keystone/schema'
import 'dotenv/config'
const databaseUrl =
process.env.DATABASE_URL || 'mongodb://localhost/keystone-project'
const sessionConfig = {
maxAge: 60 * 60 * 24 * 90,
secret: process.env.COOKIE_SECRET || 'keystone-project-secret'
}
export default config({
server: {
cors: {
origin: [process.env.FRONTEND_URL],
credentials: true
}
},
db: {
provider: 'mongoose',
url: databaseUrl
// TODO: add data seeding here
},
lists: createSchema({
// Schema items go here
}),
ui: {
// Change this for roles}
isAccessAllowed: () => true
}
// Add session values here
})
以下是来自 package.json
的项目依赖项:
{
...
"dependencies": {
"@keystone-next/admin-ui": "^14.1.3",
"@keystone-next/auth": "^31.0.0",
"@keystone-next/cloudinary": "^6.0.6",
"@keystone-next/fields": "^14.0.0",
"@keystone-next/keystone": "^24.0.1",
"@keystone-next/types": "^24.0.0",
"@keystonejs/server-side-graphql-client": "^2.1.2",
"@types/nodemailer": "^6.4.4",
"dotenv": "^10.0.0",
"next": "^11.1.0",
"nodemailer": "^6.6.3",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"stripe": "^8.169.0"
},
"devDependencies": {
"@babel/preset-env": "^7.15.4",
"@babel/preset-react": "^7.14.5",
"@babel/preset-typescript": "^7.15.0",
"@types/node": "^16.7.10",
"@typescript-eslint/eslint-plugin": "^4.29.2",
"@typescript-eslint/parser": "^4.29.2",
"babel-eslint": "^10.1.0",
"eslint": "^7.32.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-config-airbnb-typescript": "^12.3.1",
"eslint-config-prettier": "^7.2.0",
"eslint-plugin-html": "^6.1.2",
"eslint-plugin-import": "^2.24.0",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-react-hooks": "^4.2.0",
"prettier": "^2.3.2",
"typescript": "^4.3.5"
},
...
}
Keystone 6(您在此处使用的版本)尚不支持 Mongo。您需要指定 PostgreSQL (postgresql
) 或 SQLite (sqlite
) 作为数据库提供程序。
版本 6 切换为使用 Prisma 作为底层 ORM 层,为团队提供一致的方式来访问不同的数据库平台并让我们专注于更高级别的功能。
Prisma 团队正在努力添加 Mongo 支持,该功能最近 released as a preview. However some features (programmatic DB creation and some others I think) are blocking it's use with Keystone. PR #6102 tracks the progress on the Keystone side or #1277 在 Prisma 项目中结束。我无法提供和估计这将在何时登陆,但它正在积极推进中。
我正在尝试使用 MongoDB 作为数据库来设置 Keystone。在 运行 keystone-next
时,命令出错并显示以下错误消息:Error: Invalid db configuration. Please specify db.provider as either "sqlite" or "postgresql" at getDBProvider
.
他们的文档没有明确说明要将哪些值作为 db.provider
传递以使用 MongoDB 作为数据库。
以下是keystone.ts
的内容:
import { config, createSchema } from '@keystone-next/keystone/schema'
import 'dotenv/config'
const databaseUrl =
process.env.DATABASE_URL || 'mongodb://localhost/keystone-project'
const sessionConfig = {
maxAge: 60 * 60 * 24 * 90,
secret: process.env.COOKIE_SECRET || 'keystone-project-secret'
}
export default config({
server: {
cors: {
origin: [process.env.FRONTEND_URL],
credentials: true
}
},
db: {
provider: 'mongoose',
url: databaseUrl
// TODO: add data seeding here
},
lists: createSchema({
// Schema items go here
}),
ui: {
// Change this for roles}
isAccessAllowed: () => true
}
// Add session values here
})
以下是来自 package.json
的项目依赖项:
{
...
"dependencies": {
"@keystone-next/admin-ui": "^14.1.3",
"@keystone-next/auth": "^31.0.0",
"@keystone-next/cloudinary": "^6.0.6",
"@keystone-next/fields": "^14.0.0",
"@keystone-next/keystone": "^24.0.1",
"@keystone-next/types": "^24.0.0",
"@keystonejs/server-side-graphql-client": "^2.1.2",
"@types/nodemailer": "^6.4.4",
"dotenv": "^10.0.0",
"next": "^11.1.0",
"nodemailer": "^6.6.3",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"stripe": "^8.169.0"
},
"devDependencies": {
"@babel/preset-env": "^7.15.4",
"@babel/preset-react": "^7.14.5",
"@babel/preset-typescript": "^7.15.0",
"@types/node": "^16.7.10",
"@typescript-eslint/eslint-plugin": "^4.29.2",
"@typescript-eslint/parser": "^4.29.2",
"babel-eslint": "^10.1.0",
"eslint": "^7.32.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-config-airbnb-typescript": "^12.3.1",
"eslint-config-prettier": "^7.2.0",
"eslint-plugin-html": "^6.1.2",
"eslint-plugin-import": "^2.24.0",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-react-hooks": "^4.2.0",
"prettier": "^2.3.2",
"typescript": "^4.3.5"
},
...
}
Keystone 6(您在此处使用的版本)尚不支持 Mongo。您需要指定 PostgreSQL (postgresql
) 或 SQLite (sqlite
) 作为数据库提供程序。
版本 6 切换为使用 Prisma 作为底层 ORM 层,为团队提供一致的方式来访问不同的数据库平台并让我们专注于更高级别的功能。
Prisma 团队正在努力添加 Mongo 支持,该功能最近 released as a preview. However some features (programmatic DB creation and some others I think) are blocking it's use with Keystone. PR #6102 tracks the progress on the Keystone side or #1277 在 Prisma 项目中结束。我无法提供和估计这将在何时登陆,但它正在积极推进中。