How to execute js file to iterate a mongo collection

0

I know it's a very generic question but this is a concept, I'm not sure since I've run everything, I've created a mongo collection with mongoImport and there I can find and find everything from the mongo shell, making node file.js runs line by line my js file but if I want to access a collection and iterate it they said it is something like mongo baseDeDatos Coleccion archivo.js . if in file.js I have: db.employees.find().forEach(employee => print(JSON.stringify(employee))) in which employee is each element of my collection that I must do more in the console to make that print, is executing mongo baseDeDatos Coleccion archivo.js from WHERE SHELL? from the mongo? from node? I do not have clear concepts. It would be great help if you explain to me. Thank you very much

    
asked by Francisco Manrique de lara 19.06.2018 в 11:41
source

1 answer

0

From the Mongo shell (Console / Robo3T) you can execute javascript sentences:

For example, run the previous statement in Robo3T and it did not return results because I do not have the collection and much less organized that way haha, but the result was that there are no results to show.

I do not use NodeJS, but I suppose the previous command can also be executed from Javascript by connecting to the MongoDB server.

Greetings.

    
answered by 04.08.2018 в 21:07