V
V
Vetal Matitskiy2016-06-15 09:02:45
JavaScript
Vetal Matitskiy, 2016-06-15 09:02:45

How to connect to mongodb from client side javascript?

Good afternoon, dear JavaScript gurus. Is it possible to directly connect to mongodb from client side javascript? I have a large mongodb database and I wanted to directly read data from it for display in a web application without unnecessary intermediaries on the backend. among mongodb-drivers I found only those written for node.js, but not for client-side JavaScript. Are there options to connect directly from the browser? I found similar questions on the forums, but there was only chatter on the topic that such options are not needed at all and no connection examples

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaly, 2016-06-15
@vshvydky

Vetal Matitskiy: in my opinion, you are too lazy to run the rest api, let's reason, the data fetch load will be stored on the server in any case, giving such opportunities to the frontend you deprive yourself of control over the number of requests, their correctness, and as a result create an uncontrolled load on the database. Cons that I see, the number of simultaneous connections to the database can be huge, why flood yourself? 2. any request outside your logic can use lookups for non-indexed data, which can lead to blocking. 3. you will give the client a login and password for reading, what he will do with them after that only he knows. Now about the advantages of using the backend to be completely lazy, as an option, we put a node and install the sails.js framework, install the project, get a ready-made base for the backend api, generate an api controller, we describe the model and what it will produce, here is a selection from the database, and we teach the client to draw all this in the frontend. It is possible through the same Angular.
Of course, I understand that this is not an answer to your question, but you cannot find a solution precisely because it should not be decided that way.
For example, sails new Project will create a project
sails generate api post will create a fullrest api with the described methods find, findOne, create, update, destroy, populate, add, remove,
disable unnecessary ones and you're done.
Of course, I understand that it seems superfluous to keep the backend, but when you receive 5-10 requests for a full selection of huge tables at the same time, your server will wait and start refusing to receive data from clients, you will understand that you have come to the wrong place and you will be all remodel in a hurry.
Naturally sails is not required to use, you can find a bunch of other solutions.
Here is the first answer from Google:https://www.npmjs.com/package/restful-api
In any case, I recommend 10 times to think before giving such functionality to the frontend. And yes, if you do not change your mind, send a link to the finished project. maybe your data will seem useful to me and I will download it entirely))))

R
Runic_Elf, 2018-08-09
@Runic_Elf

On the forms you were advised the most correct solution.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question