Search code examples
javascriptmongodbjobs

How to do jobs for mongodb with javascript


The database is configured with a Mongo sharding with 3 Shards. (TestSharding). The database is configured with a Mongo sharding with 3 Shards. (TestSharding) and the script can be javascript.

I have to do a job that determines if there is a .json or .csv file and imports it into a Mongo database. But I don't know how to do a job. Can somebody help me?


Solution

  • Basically you want to interact your local file with the mongodb instance. You want to look for interface that allows you to do so.

    There are two simple way you can achieve that:

    1. For simple tasks, mongo command line tool mongoimport https://docs.mongodb.com/manual/reference/program/mongoimport/
    2. Using custom program (e.g. nodejs) With custom program you will need a specific driver to connect to local filesystem and the mongodb instance. In nodejs, you can use the fs and mongodb(https://www.npmjs.com/package/mongodb) module