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 8520483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:32:57+00:00 2026-06-11T06:32:57+00:00

I am using mongo and node.js in an application. The mongo database consists of

  • 0

I am using mongo and node.js in an application. The mongo database consists of two servers.

In the example given in http://howtonode.org/express-mongodb, i can connect to one server using:

ArticleProvider = function(host, port) {
 var database = 'node-mongo-blog';
 this.db= new Db(database, new Server(host, port, {auto_reconnect: true}, {}));
 this.db.open(function(){});
};

But how can I connect to multiple servers, in my case there are two servers.

  • 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-11T06:32:59+00:00Added an answer on June 11, 2026 at 6:32 am

    Sample code from
    https://github.com/christkv/node-mongodb-native/blob/master/examples/replSetServersQueries.js.

    The servers specified is only the seed list – it will discover the complete list automatically. The member of a replica set are not static – they will change (a new server might get added or an existing server might be removed). The client connects to one of the servers specified in the input list and then fetches the replica set members from that. So you don’t have to list all the server addresses here – if at least one of the servers mentioned in the list is up and running it will find the rest automatically.

    var port1 = 27018;
    var port2 = 27019;
    var server = new Server(host, port, {});
    var server1 = new Server(host, port1, {});
    var server2 = new Server(host, port2, {});
    var servers = new Array();
    servers[0] = server2;
    servers[1] = server1;
    servers[2] = server;
    
    var replStat = new ReplSetServers(servers);
    console.log("Connecting to " + host + ":" + port);
    console.log("Connecting to " + host1 + ":" + port1);
    console.log("Connecting to " + host2 + ":" + port2);
    var db = new Db('node-mongo-examples', replStat, {native_parser:true});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have built my application using node.js, mongodb, redis, express, socket.io and planning to
Im having some issues with deleting an entry from mongo DB. Im using node-mongodb-native
I am currently playing around with node.js and MongoDB using the node-mongo-native driver. I
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
I'm using perl and MongoDB::GridFS (along with other mongo modules) to store and retrieve
I am using django-nonrel, Postgre as a database and Mongo as file store. my
I'm trying to implement blog post storage using mongo db. I've got two domain
I'm using MongoDB with Node.js. Is there any speed advantage to using a MapReduce
As a preface, I'm using Node.js with Mongo-db-native. I'm also using GridFS to store
I'm using Mongoose to manage a Mongo database. My connection file is quite simple:

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.