Here is my code:
const MongoClient = require('mongodb').MongoClient;
const assert = require('assert').strict;
const url = 'mongodb://localhost:27017/'; // I have also tried 'mongodb://localhost:27017/testdb' but it do not work either
const dbname = 'testdb';
MongoClient.connect(url, { useUnifiedTopology: true }, (err, client) => {
assert.strictEqual(err, null);
console.log('Connected correctly to server');
const db = client.db(dbname);
db.dropCollection('testTable', (err, result) => {
assert.strictEqual(err, null);
console.log('Dropped Collection', result);
const collection = db.collection('testTable');
collection.insertOne({name: "First Data Inserted", description: "Test"},
(err, result) => {
assert.strictEqual(err, null);
console.log('Insert Document:', result.ops);
collection.find().toArray((err, docs) => {
assert.strictEqual(err, null);
console.log('Found Documents:', docs);
client.close();
});
});
});
});
I downloaded Robo 3T (well now Studio 3T) and I can connect and make changes through there, but for some reason I can't connect via my Nodejs app, I have my db running on the background
As soon as I start my app, it waits for 2 seconds and then throws an error, I have tried to remove the assert but it still fails
Any input would be a lot of help!