盖茨比支持MongoDB关系吗?
我正在建立一个个人博客,之所以选择盖茨比,是因为显而易见的原因(性能和容易上手),也因为我对前端有一些背景知识。此外,我还构建了一个简单的应用程序来创建我的内容(html字符串),并使用express server将其存储在MongoDB数据库中。现在在博客中,我只是尝试使用盖茨比支持MongoDB关系吗?,mongodb,graphql,gatsby,Mongodb,Graphql,Gatsby,我正在建立一个个人博客,之所以选择盖茨比,是因为显而易见的原因(性能和容易上手),也因为我对前端有一些背景知识。此外,我还构建了一个简单的应用程序来创建我的内容(html字符串),并使用express server将其存储在MongoDB数据库中。现在在博客中,我只是尝试使用gatsby-source-MongoDBplugin从MongoDB中提取数据 我的MongoDB模式有关系。例如,“Post”架构有一个“user”属性,该属性是引用“user”架构中的用户的ObjectID。我对gat
gatsby-source-MongoDB
plugin从MongoDB中提取数据
我的MongoDB模式有关系。例如,“Post”架构有一个“user”属性,该属性是引用“user”架构中的用户的ObjectID。我对gatsby source mongodb的配置如下所示:
{
resolve: 'gatsby-source-mongodb',
options: {
dbName: 'KathaDB',
collection: 'posts',
server: {
address: "somecluster",
port: 27017
},
auth: {
user: 'someuser',
password: 'somepasswd'
},
extraParams: {
replicaSet: 'test',
ssl: true,
authSource: 'admin',
retryWrites: true,
preserveObjectIds: true
}
}
}
我有几个问题:
preserveObjectId:true
添加到您的插件选项中:
{
resolve: "gatsby-source-mongodb",
options: {
dbName: "KathaDB",
collection: "posts",
server: {
address: "somecluster",
port: 27017,
},
auth: {
user: "someuser",
password: "somepasswd",
},
extraParams: {
replicaSet: "test",
ssl: true,
authSource: "admin",
retryWrites: true,
preserveObjectIds: true,
},
preserveObjectIds: true, // <= here
},
};
{
决议:“盖茨比源mongodb”,
选项:{
dbName:“KathaDB”,
收集:“帖子”,
服务器:{
地址:“somecluster”,
港口:27017,
},
认证:{
用户:“someuser”,
密码:“somepasswd”,
},
外部参数:{
复制集:“测试”,
是的,
authSource:“管理员”,
retryWrites:没错,
是的,
},
PreserveObjectId:true,//确实如此
MongoDB依赖ObjectId建立关系,因此您可能需要将preserveObjectId:true
添加到您的插件选项中:
{
resolve: "gatsby-source-mongodb",
options: {
dbName: "KathaDB",
collection: "posts",
server: {
address: "somecluster",
port: 27017,
},
auth: {
user: "someuser",
password: "somepasswd",
},
extraParams: {
replicaSet: "test",
ssl: true,
authSource: "admin",
retryWrites: true,
preserveObjectIds: true,
},
preserveObjectIds: true, // <= here
},
};
{
决议:“盖茨比源mongodb”,
选项:{
dbName:“KathaDB”,
收集:“帖子”,
服务器:{
地址:“somecluster”,
港口:27017,
},
认证:{
用户:“someuser”,
密码:“somepasswd”,
},
外部参数:{
复制集:“测试”,
是的,
authSource:“管理员”,
retryWrites:没错,
是的,
},
PreserveObjectId:true,//谢谢,它起作用了。我认为extraParams中的PreserveObjectId属性会起作用。谢谢,它起作用了。我认为extraParams中的PreserveObjectId属性会起作用。