小编Vis*_*kur的帖子

连接到 MongoDB Atlas 集群错误

我在通过 Node.js、express 和 mongoose 连接到我的 MongoDB Atlas 集群时遇到问题:

{ MongoNetworkError: connection 4 to mongodb-passport-auth-shard-00-00-vp7yg.mongodb.net:27017 closed
    at TLSSocket.<anonymous> (C:\Users\Vishesh\Documents\Projects\nodejs-passport-auth\node_modules\mongodb-core\lib\connection\connection.js:276:9)
    at Object.onceWrapper (events.js:273:13)
    at TLSSocket.emit (events.js:187:15)
    at _handle.close (net.js:606:12)
    at TCP.done (_tls_wrap.js:386:7)
  name: 'MongoNetworkError',
  errorLabels: [ 'TransientTransactionError' ],
  [Symbol(mongoErrorContextSymbol)]: {} }
Run Code Online (Sandbox Code Playgroud)

这是我用于通过短 SRV 连接字符串连接到我的集群的代码:

mongoose
  .connect(
    'mongodb+srv://myname:mypwd@myapp-vp7yg.mongodb.net/test?retryWrites=true',
    { useNewUrlParser: true }
  )
  .then(() => console.log("Connected to mongodb..."))
  .catch(err => console.log(err));
Run Code Online (Sandbox Code Playgroud)

mongoose mongodb mongodb-atlas

9
推荐指数
2
解决办法
7646
查看次数

在JS中将数组中的相同值分组到数组中

如何将数组中的相同数字分组到数组中?

我有以下数字数组:

var arr = [1,1,1,1,2,2,3,3,3,4,5,5,6];
Run Code Online (Sandbox Code Playgroud)

我的输出应该是

[[1,1,1,1],[2,2],[3,3,3],4,[5,5],6]
Run Code Online (Sandbox Code Playgroud)

javascript arrays

3
推荐指数
1
解决办法
1万
查看次数

SyntaxError: Unexpected token &lt; in JSON at position 0 when testing in Graphiql

我正在学习 GraphQL 并且是该技术的新手。我无法找出此语法错误的原因。当我在 graphiql 上对其进行测试时,它会引发意外的令牌语法错误

这是我的 server.js:

const express = require("express");
const graphqlHTTP = require("express-graphql");
const schema = require("./schema");

const app = express();
app.get(
  "/graphql",
  graphqlHTTP({
    schema: schema,
    graphiql: true
  })
);

app.listen(4000, () => {
  console.log("Server listening to port 4000...");
});
Run Code Online (Sandbox Code Playgroud)

这是我的架构:

const {
  GraphQLObjectType,
  GraphQLString,
  GraphQLInt,
  GraphQLSchema,
  GraphQLList,
  GraphQLNotNull
} = require("graphql");

// HARD CODED DATA
const customers = [
  { id: "1", name: "John Doe", email: "jdoe@gmail.com", age: 35 },
  { id: "2", name: "Kelly James", email: …
Run Code Online (Sandbox Code Playgroud)

graphql express-graphql

3
推荐指数
1
解决办法
3632
查看次数