const express = require('express'); const app = express();
var MongoClient = require('mongodb').MongoClient; var url = "mongodb://192.168.0.60:27017/";
MongoClient.connect(url, function(err, db) { if (err) throw err; var dbo = db.db("database"); var cursor = dbo.collection('data').find();
dbo.collection("data").findOne({}, function(err, result) {
app.get('/', (req, res) => {
res.json(result);
console.log(result)
res.end();
db.close();
});
});
});
app.listen(8000, () => { console.log('Example app listening on port 3000!'); });
I made a data collection like this...
If nodejs is executed, even if the data in mongodb is changed. It doesn't change on localhost:8000.
What should I do?
dbo.collection ("data") in the callback of app.get.FindOne must be called.
585 PHP ssh2_scp_send fails to send files as intended
621 GDB gets version error when attempting to debug with the Presense SDK (IDE)
631 Uncaught (inpromise) Error on Electron: An object could not be cloned
926 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2024 OneMinuteCode. All rights reserved.