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).