mongo driver have something like middleware to resolve switch hosts ip

31 views
Skip to first unread message

赵玄

unread,
Jan 21, 2016, 1:39:54 AM1/21/16
to node-mongodb-native
Hi Christaian

     mongo driver have something like middleware to resolve switch hosts ip?

     i have a question about mongo driver, when i use domain name connect mongo server, i switch hosts file,  find my logic server work well, i am not understand, because i use connect pool in my logic server, i think driver use TCP connect mongo server, why my logic server have nothing affect?  unless , driver use RPC server between mongo server and logic server. but i am not found in mogodb package.

Please guide me on this issue.




Christian Kvalheim

unread,
Jan 21, 2016, 3:51:54 AM1/21/16
to node-mongodb-native
I'm not sure what you are asking about, can you outline what you are doing in steps ?

赵玄

unread,
Jan 21, 2016, 4:17:47 AM1/21/16
to node-mongodb-native
i am sorry for my poor english,

step1: in hosts
test.mongo     10.21.3.44
step2: chang hosts
test.mongo      10.21.3.45
step3: stop 3.44 mongo server

db.test.insert({name:44})
my logic server:
var MongoClient = require('mongodb').MongoClient;
var url = 'mongodb://test.mongo:27017/larvel';

MongoClient.connect(url, function (err, db) {
var collection = db.collection('test');

setInterval(function () {
collection.findOne({}, function (err, res) {
console.log('res is ', res.name);
})
}, 1000)
})
result :

res is 44.
res is 44.
res is 44.
res is 44.
res is 45.
res is 45.
res is 45.
res is 45.

i want to know ,the driver how deal with it. why my logic server have not affect.

在 2016年1月21日星期四 UTC+8下午4:51:54,Christian Kvalheim写道:

Christian Kvalheim

unread,
Jan 21, 2016, 4:57:56 AM1/21/16
to node-mongodb-native
The answer unfortunately it no, you have to restart the node application for it to pick up the new DNS resolution. I'm not aware of any way around this.

赵玄

unread,
Jan 21, 2016, 10:17:40 PM1/21/16
to node-mongodb-native
thanks a lot for your explain.  

but i found two way to pick up the new DNS, 
1. as you say ,restart my node application;
2. stop first DNS ip 

i find when i change to second DNS, the result is not change , but when i stop first mongo server, the result return one or two null,and continue return the second mongo server result. i want to know how the driver work, is there have some RPC between mongo server and my node application, why my node application not crash for mongo server confused . 


在 2016年1月21日星期四 UTC+8下午5:57:56,Christian Kvalheim写道:

Christian Kvalheim

unread,
Jan 22, 2016, 3:56:44 AM1/22/16
to node-mongodb-native
Stopping and restart the mongod processes would work as you discovered as they force the driver to reconnect.

You can find more information about how our drivers work here

赵玄

unread,
Jan 24, 2016, 9:16:28 PM1/24/16
to node-mongodb-native
thank you very much :) , i will back after read doc done.

在 2016年1月22日星期五 UTC+8下午4:56:44,Christian Kvalheim写道:

赵玄

unread,
Jan 25, 2016, 3:40:49 AM1/25/16
to node-mongodb-native
i found the answer.

the driver hold the socket err,  and resending the query. so this not affect my application. that is so comfortable. i will watching the driver and star. 

thank you again.

在 2016年1月25日星期一 UTC+8上午10:16:28,赵玄写道:
Reply all
Reply to author
Forward
0 new messages