返回

异步Javascript函数未运行

发布时间:2022-04-20 18:35:32 211
# 前端
 
我正在尝试运行一个具有

慰问。日志(“heo”);

但这不管用

它不起作用有什么原因吗?我正在尝试连接mongodb Atlas云服务。

console.log("hell");
const dotenv = require('dotenv')
dotenv.config()
//const mongodb = require('mongodb')
const mongodb = require('mongodb').MongoClient;

const { MongoClient } = require("mongodb");
console.log("hel");
const uri = process.env.CONNECTIONSTRING;

const client = new MongoClient(uri);
console.log("he");
async function run() {
  console.log("heo");
  await client.connect();
  const db = client.db("blah")
  console.log("h");
  const results = await db.collection("student").find().toArray()
  console.log(results)
  console.log("hello")
}
//call function
run()

任何帮助都将不胜感激。

谢谢


指数js

console.log("001");
 dotenv = require('dotenv');
dotenv.config();
const mongodb = require('mongodb').MongoClient;

const { MongoClient } = require("mongodb");
console.log("002");
const uri = process.env.CONNECTIONSTRING;

const client = new MongoClient(uri);
console.log("003");
async function run() {
  catch{
  console.log("004");
  client.connect();
  const db = client.db("blah");
  console.log("005");

  const results = await db.student.find();
  console.log("006")

  console.log(results)
  console.log("007")
  client.close()

    console.log("hello");
  }
  try{}
  };


//call function
run();

我在航站楼用,

node index.js

我认为catch{}try{}块不正确。

特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(0)
按点赞数排序
用户头像