'Connecrint to Mongodb
I just can't connect to a mongodb. Here's what I tried
in node.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() {
console.log("004");
client.connect();
const db = client.db("blah");
console.log("005");
await const results = db.student.find();
console.log("006")
console.log(results)
console.log("007")
client.close()
};
//call function
run();
and I get this error
SyntaxError: Unexpected token 'const'
the CONNECTIONSTRING is in .env beside the original file node.js
The database is called 'blah' and the collection 'student'.
The error is on line 18,
await const results = db.student.find();
Thanks,
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
