I
I
Ingerniated2018-04-11 18:38:05
Node.js
Ingerniated, 2018-04-11 18:38:05

How to send a command for the database from the client to the server?

Hello everyone, tell me how to send commands from the client to the server for execution?
For example, create a collection

MongoClient.connect(url, function(err, db) {
  if (err) throw err;
  var dbo = db.db("mydb");
  dbo.createCollection("customers", function(err, res) {
    if (err) throw err;
    console.log("Collection created!");
    db.close();
  });
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Egor Zhivagin, 2018-04-11
@Ingernirated

1) You make some kind of route on the backend that will accept requests to a specific address.
2) Through this route, you process the request, get what you need from the database, ... and return the answer with the data
3) On the client, you just need to throw an ajax request to the address of the route
Or did I misunderstand the question?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question