我正在尝试连接到我的 MongoDB 数据库,但收到此错误
ReferenceError: require is not defined
at file:///Users/admin/mjml/mjml/playground.js:1:21
at ModuleJob.run (node:internal/modules/esm/module_job:146:23)
at async Loader.import (node:internal/modules/esm/loader:165:24)
at async Object.loadESM (node:internal/process/esm_loader:68:5)
const MongoClient = require('mongodb').MongoClient
const uri =
'------------------------------'
const client = new MongoClient(uri, { useNewUrlParser: true })
client.connect((err) => {
const collection = client.db('test').collection('devices')
// perform actions on the collection object
client.close()
})
繁星coding
相关分类