首页 > 解决方案 > 如何解决 mongodb 连接中发生的意外令牌错误?

问题描述

我已经编写了假设连接到 mongo DB 的代码。但是在运行代码时出现以下错误;

代码 -

    // Create a new MongoClient
    //const client = new MongoClient (uri);

      function run () {
        const uri =
  'URI value ';
  const client = new MongoClient(uri);
      try {
        // Connect the client to the server
        await client.connect ();
        // Establish and verify connection
        await client.db ('snapp_transactions').command ({
          ping: 1
        });
        log.info ('Connected successfully to server');
      } finally {
        // Ensures that the client will close when you finish/error
        await client.close ();
      }
    }

    

ERROR MESSAGE -

    ERROR: Unexpected token {
    internetexplorer
    C:\Users\MOHAS076\SBC-trp-web-test-automation\src\step-definitions\Web\when.js:88
          } catch {

节点版本 - 8.12

标签: node.jsmongodb

解决方案


推荐阅读