Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8946455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:31:16+00:00 2026-06-15T12:31:16+00:00

How to connect to MongoDB with Node.js? And then pass the result to a

  • 0

How to connect to MongoDB with Node.js? And then pass the result to a client side JavaScript and display in HTML.

var http = require('http');
var URL = require('url');
var Db = require('mongodb').Db;
var Server = require('mongodb').Server;
var client = new Db('people', new Server("127.0.0.1", 27017, {}), { safe: false });

client.open(function (err, client) {
  client.collection('people', listAllData);
});

var listAllData = function (err, collection) {
  collection.find().toArray(function (err, results) {
    console.log(results);
  });
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:31:19+00:00Added an answer on June 15, 2026 at 12:31 pm

    You should use Mongoose – elegant mongodb object modeling for node.js. http://mongoosejs.com

    The quickstart guide is really cool, you should read it.

    According to the documentation, here is a small example of how to use Mongoose:

    var mongoose = require('mongoose');
    var db = mongoose.createConnection('localhost', 'test');
    
    var schema = mongoose.Schema({ name: 'string' });
    var Cat = db.model('Cat', schema);
    
    var kitty = new Cat({ name: 'Zildjian' });
    kitty.save(function (err) {
      if (err) // ...
      console.log('meow');
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

... (... = some unrelated code) var mongoose = require('mongoose'); var db = mongoose.connect('mongodb://localhost/test');
Quite simply, I'm trying to connect to a MongoDB via Node.js: Db = require('../v2/node_modules/mongodb').Db
How do I connect to mongodb with node.js? I have the node-mongodb-native driver. There's
I'm using the node-mongodb-native driver with connect-session-mongo . When I use connect-session-mongo with the
I'm using Doctrine ODM to connect to MongoDB. I have a three node replica
Let say I have a node.js server connecting to a mongoDB. Then the mongoDB
i'm using node 0.4.11 express 2.4.6 mongodb 1.8.3 mongoose 2.1.2 connect-mongodb 1.0.0 and trying
In file app.js i have: , mongoose = require('mongoose') , db = mongoose.connect('mongodb://localhost/expressdb'); app.get('/',
I'm using Mongoosejs to connect with MongoDB. Consider the following contrived example of a
I have the following code to connect to MongoDB: try { $m = new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.