盖茨比支持MongoDB关系吗?

盖茨比支持MongoDB关系吗?,mongodb,graphql,gatsby,Mongodb,Graphql,Gatsby,我正在建立一个个人博客,之所以选择盖茨比,是因为显而易见的原因(性能和容易上手),也因为我对前端有一些背景知识。此外,我还构建了一个简单的应用程序来创建我的内容(html字符串),并使用express server将其存储在MongoDB数据库中。现在在博客中,我只是尝试使用gatsby-source-MongoDBplugin从MongoDB中提取数据 我的MongoDB模式有关系。例如,“Post”架构有一个“user”属性,该属性是引用“user”架构中的用户的ObjectID。我对gat

我正在建立一个个人博客,之所以选择盖茨比,是因为显而易见的原因(性能和容易上手),也因为我对前端有一些背景知识。此外,我还构建了一个简单的应用程序来创建我的内容(html字符串),并使用express server将其存储在MongoDB数据库中。现在在博客中,我只是尝试使用
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
        }

      }
  }
我有几个问题:

  • 当我查询时,我从我的“Post”模式中获取所有属性,但在响应中没有“user”属性。我不知道这是否是由于财产的类型。我挖了一点,发现了一个类似的问题。看起来他们通过保留ObjectID解决了这个问题,但我甚至没有得到ObjectID类型的属性
  • 另外,这个插件支持关系吗?例如,在给定“用户”数据的ObjectID时,是否可以获取该数据 是的

    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,//确实如此

    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属性会起作用。