Tuesday 18 July 2017

Using Node to act as a middleman between browser and mongoDB

Hey there,I've never used node before and a bit stuck. I'm trying to populate some graphs in a browser using data in a mongoDB collection. I've read around and using Node to assist with this seemed the way to go. I am a bit unfamiliar with how it works and was hoping for some hints.var http = require('http'); var client = require('mongodb').client; var url = "mongodb://*removed*"; client.connect(url, function(err, db) { if (err) throw err; var query = {id : "*removed*"}; db.collection("*removed*").find(query).toArray(function(err, result) { if (err) throw err; console.log(result); db.close(); }); }); I found this example online and is working fine. I'm a bit confused by two points:Does this file sit on the server with the Db and I just call this file?How can I alter query so that I can search whatever I want from the browser and have it return?I'm still searching for solutions on the second one but I'm not sure how the node file is situated. Any help would be appreciated.Thanks!

Submitted July 18, 2017 at 08:43AM by Fluroblue

No comments:

Post a Comment