JQuery client application with MongoDB

I am trying to write a very simple sample application to become familiar with using MongoDB. Essentially, I would like to have one webpage that requests a local MongoDB server, dynamically adding and removing content using jQuery. I have no problem dropping the page layout and jQuery, but part of the MongoDB equation is confusing me more and more. I understand that MongoDB is a server and works remotely from the client, but for my example, I just want to be able to quickly and easily request a client-side JavaScript browser:

$("#toggle").click(function() { if ($(this).is(":checked") { // add items from mongodb addItems(mongodb.test.find({ age: { $gt: 5 }})); } else { $("#results").hide(); } }); 

Is there a way to interact with MongoDB this way?

+4
source share
2 answers

You need a driver to connect to the MongoDB server. The list of drivers is here: http://www.mongodb.org/display/DOCS/Drivers

There is a JS driver, but only for the server side of JS - in particular node.js

At the bottom, you cannot connect directly to the browser. You need a server side component.

+7
source

As @balafi reports, you need a driver.

MongoDB has a REST interface, and it has drivers like Mongoose that are designed to create a fully functional REST interface for MongoDB.

This could be the route if you want to use MongoDB without any server configuration issues. That way, you simply call the POST or GET call from jQuery with the specified parameters that you want.

Further information on REST interfaces can be found here: http://www.mongodb.org/display/DOCS/Http+Interface

However, I must warn you that the built-in MongoDB is sorely lacking and is intended only for extremely simple queries.

+5
source

Source: https://habr.com/ru/post/1438289/


All Articles