Import CSV File Data Into MongoDB In Node
Setup Folder
Open the command prompt and create new folder using the following command followed by folder name.
- mkdir csv
- cd csv
Setup Node In Folder
To setup node in folder use the following command
- npm init -y
This package.json file will contain the metadata related to our project.
The package.json will look like this
Install Packages
Now we have to install packages to be used to build our application.
To install packages we use the following command followed by package name.
- npm install csvtojson express ejs mongoose multer body-parser
After installation package.json will look like this
Add New Folders
Add few new folders in our project folder
- models
- public
- views
Models Folder
Add new file in it and name it as csv.js
This file will contain our collection(table) schema.
csv.js
Views Folder
Add new file and name it demo.ejs
demo.ejs
Open the package.json and in scripts add "start":"node app.js"
And file will now look like this
Starting Point
Now we have to set the starting point of our application.
Add new file and name it app.js and add the below code in it.
app.js
Open the package.json and in scripts add "start":"node app.js"
And file will now look like this
CSVFile
this file is to be uploaded for filling data in mongodb
Download Code From here
Comments
Post a Comment