Can I create js files that execute mongodb commands?

0

The issue is that I want to create some scripts that receive parameters to later perform operations like CRUD.

For example, having an application developed in x language, when wanting to make an operation to the DB, the request is sent to the file that contains the javascript and mongo commands. Example_mongo.js:

var x = "valor obtenido desde el archivo solicitante, puede ser un documento (formato JSON)";

db.mi_coleccion.insert(x); 
    
asked by J.Correa 24.11.2016 в 19:10
source

1 answer

2

If you want to use mongo in a js file you need to use a driver since you are programming in x machine but you are not connected to mongo

first mongo is a sgbd and when you install it you can be running the server that saves the data and is not using the client which consults your information, What is the customer? in my case it is the terminal (when you execute the command mongo and not mongod which is the server) in other cases is robomongo , etc ..

the clients execute a connection to 127.0.0.1:27017 and they pass the queries that you have to the server so that you return the information

so as I mentioned, it is necessary to use a driver like the mongo native for nodejs or the driver of mongoose there, you can already say that it makes the connection to a certain db and make queries as if it were a terminal , and if you want to make a program in any language, you have to make a server and create a api (but that's another topic).

    
answered by 16.01.2017 / 20:41
source