Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
252 views
in Technique[技术] by (71.8m points)

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...