首页 > 解决方案 > 使用 mongoDB 10000 毫秒后,GraphQL 端点缓冲超时

问题描述

我正在尝试使用以下代码将我的 GraphQL 端点与 MongoDB 配对:

const express = require('express');
const { graphqlHTTP } = require('express-graphql');
const schema = require('../schema/schema');
const { MongoClient } = require('mongodb');

const app = express();
const PORT = 3000;

app.use('/graphql', graphqlHTTP({
    schema,
    graphiql: true
}));

const uri = 'mongodb+srv://<USER_NAME>:<PASSWORD>@mysuperheroes.ucexn.mongodb.net/myFirstDatabase?retryWrites=true&w=majority';
const client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true });
client.connect().then(
    app.listen(PORT, (err) => {
        err ? console.log(err) : console.log('Server started!');
    })
);

我怀疑问题出在查询或模式上,很可能存在连接问题,因此附上连接文件和错误消息。我得到的错误:Operation movies.find() buffering timed out after 10000ms

GraphQL 查询:

query {
  movies {
    name
  }
}

标签: javascriptreactjsmongodbapigraphql

解决方案


推荐阅读