Can angularjs connect directly to mongodb?

I am new to angularjs and as the title says I am wondering if there is a way to connect angular js directly to mongodb without coding additional backend using express.js. I tried to search the internet but I cannot find any resources.

+3


source to share


2 answers


Sorry you are trying to make this impossible. You will need to introduce some server-side technology so that you can talk to the database and form some kind of api that will return JSON data depending on certain business rules coded into the backend of your application. AngularJS has built-in templates that take JSON data and post it as you cast it around the entire DOM.

What you are asking is logical, I also asked this question from the outside world. If this side code is serverless, wherever it appears, database queries will be displayed to the user on the client side. The client can then change the syntax of the AngularJS request in the code inspector. BAM ... now all data stored in your database is now available to the user. In any case, this could mean that the user can perform the removal of ops and whatnot. Anyway, I hope this sheds some light on this topic for you! Here are two resources that helped me on this server / client:



http://tomdale.net/2015/02/youre-missing-the-point-of-server-side-rendered-javascript-apps/

https://medium.com/google-developers/tradeoffs-in-server-side-and-client-side-rendering-14dad8d4ff8b

+5


source


Angular can use MongoJS to connect to MongoDB.

Installing MEAN

>Npm init
>npm install express body-parser ejs mongojs --save

      




 Todos.js

 var db = mongojs('mongodb://eman:eman@127.0.0.1:27017/todos',['tasks']);
 db.tasks.find( function(err, tasks)  {
    if (err) {
       res.send(err);
    }else {
       res.json(tasks);
    }
  });

//IP and Port can be seen when from your terminal when you run "MONGO"

      




You need to install MongoDB from localhost.

0


source







All Articles