Wednesday, June 12, 2024

How to connect with Mongodb with Nodejs and fetching data?

import csv to mongodb node js

Hello to all, welcome to In this post, I will tell you, How to connect with Mongodb with Nodejs and fetching data?

MongoDB is NoSQL database. Now I am learning this and this is very interesting and I am going to share some working examples.

We can also save the mongodb data into custom json file and this feature makes mongodb better.

Mongodb data with command prompt query:

mongodb data with command prompt query

Here is the working coding steps you need to follow:

1. First you need to run below query to install mongodb into your node app:

$ npm install mongodb

2 . Here is the code you need to add into testcode.js(you can choose you name) file:

var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/";
MongoClient.connect(url, function(err, db) {
  if (err) throw err;
  var dbo = db.db("test");
  dbo.collection("test").findOne({}, function(err, result) {
    if (err) throw err;

3. After this, run below command into your terminal and see the output:

$ node testcode.js
node output with data

Now this is it, if you have any query related to this post then do comment below or ask question.

Thank you,

ludhiana wala ajay,


the authortherichpost
Hello to all. Welcome to Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 14, Angular 15, Angular 16, Angular 17, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.