U kunt de verschillende collecties gebruiken met db.collection('name').find({})
Hier is de code die ik heb geprobeerd
App.js
const express = require('express');
const bodyParser = require('body-parser');
const MongoClient = require("mongodb").MongoClient;
const assert = require('assert');
const url = 'mongodb://localhost:27017';
var db;
MongoClient.connect(url, { useNewUrlParser: true }, function (err, client) {
assert.equal(null, err);
console.log("Connected successfully to DB");
db = client.db('name of the db');
});
var app=express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.get('/test/:collection', function(req,res){
let collection = req.params.collection;
console.log(collection);
db.collection(collection).find({}).toArray( function (err, result) {
res.send(result);
});
});
var port = 8000
app.listen(port, '0.0.0.0', () => {
console.log('Service running on port ' + port);
});
Ik hoop dat dit helpt