isage / lua-resty-moongoo

MongoDB library for OpenResty
Do What The F*ck You Want To Public License
117 stars 33 forks source link

Querying a secondary in a replica set #4

Open travisbell opened 7 years ago

travisbell commented 7 years ago

Hi there,

I just have some questions around replica sets and more information about the docs where you say that you can't query a slave.

I'm in the process of wanting to migrate parts of a legacy Ruby app over to OpenResty and am having trouble finding a decent library with full replica set support. One of our Ruby apps does next to no writing but heavy on the reads and we have that app to do its querying from the slave, not the master.

It doesn't sound like there's a way to do that here, is that right? If not, how much work would it be to add said support (I'd be happy to give it a try if I had an idea as to what was involved).

Thanks!

isage commented 7 years ago

There's no support yet, right. However, it shouldn't be hard to implement. First, url parser should be modified to handle mongodb://example1.com,example2.com,example3.com/?replicaSet=test&readPreference=secondary Second, we should store pool of connections with primary/slave flag, instead of just one. I'm not sure, however, that it's viable to connect to all servers defined in uri. We, basically, need two connections with readPreference=secondary : one to master, and one to a random slave. And one connection to master otherwise (as we do now) And finally, db:_cmd shoud be modified accordingly, with list of read/write commands and proper connection selection.

pacop commented 5 years ago

Is it supported now? If I have understood this sentence correctly, now it should work just fine:

Extracted from README.MD Moongoo tries really hard to be smart, and opens connection only when needed, searches for master node in replicaset, and uses relevant to mongodb version auth mechanism.

isage commented 5 years ago

No

On Fri, 4 Jan 2019, 14:43 pacop <notifications@github.com wrote:

Is it supported now? If I have understood this sentence correctly, now it should works just fine:

Extracted from README.MD Moongoo tries really hard to be smart, and opens connection only when needed, searches for master node in replicaset, and uses relevant to mongodb version auth mechanism.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/isage/lua-resty-moongoo/issues/4#issuecomment-451422532, or mute the thread https://github.com/notifications/unsubscribe-auth/AAQtISNFcKGSm26Go8g806bZpf-awM3Hks5u_z5MgaJpZM4ODDgx .