Fetch data from MongoDB using NodeJs ----- Setting Up MongoDB----------------
- Install Mongodb 2.create data\db folder as mongodb requires a data folder to store its files. -> md data -> cd data -> md db
- open command prompt and go to mongodb\bin path and give the following command to start the mongo process
mongod --dbpath "d:\data\db"
- open another command prompt and go to mongodb\bin path and give the following command to start the mongo shell
mongo
- In mongo shell, type the following commands
i. command to create/open a database -> use ex: use mydb mydb is the databsae name ii. command to create a collection -> db.createCollection("collectionname") ex: db.createCollection("Longiin") iii. command to insert a record/document -> db..insert(records); ex: db.Longiin.insert({name:"abc",email:"[email protected]"}); iv. command to display the records from a collection -> db..find() ex: db.Longiin.find() ---- starting Node---------
- open cmd and go to path where Login.js file is and tyep
-
node login.js
- open login.html in browser and check with the values that are inserted in the database.