Thursday, 13 April 2017

Retrieving data from Mongodb with Angular

I'm trying to retrieve data from mongodb with Angular but I don't really know how to since I'm quite new to this. I'm using node.js with an Express framework. I already have my mongodb client and server running and using studio-3T for mongodb as an gui for mongo.

Here is the connection with mongodb in my app.js:

var MongoClient = require('mongodb').MongoClient

MongoClient.connect('mongodb://localhost:27017/', function (err, db) {
  if (err) throw err

  db.collection('loodgieters').find().toArray(function (err, result) {
    if (err) throw err
    else if (result.length) {
      result.render('loodgieters', {
        "loodgieters" : result
      });  
    }
    console.log(result);  
  });
});

In mongodb I have added a collection named "loodgieter". key: hometext. value: this is some text

Now, I need to use angular to somehow access this collection and show the data in my html page

Anyone an idea?



via Larsmanson

No comments:

Post a Comment