Can the seed list in my connection string be a superset of the actual replicaset?

41 views
Skip to first unread message

mo

unread,
Apr 5, 2012, 10:17:15 AM4/5/12
to mongodb-csharp
That way, I can put my development machines in the connection string
along with production machines, and not have to change back and forth
when going from testing to deployment.

I've tried it out like this, and it seems to work fine. I'm just
wondering if anyone with more experience with mongo or the csharp
driver might know any reason why this would be A Really Bad Idea?

Thanks!
Mo

Scott Hernandez

unread,
Apr 5, 2012, 10:19:52 AM4/5/12
to mongodb...@googlegroups.com
It is fairly bad idea if you can ever connect to both sets at the same
time from your app.

You may wan to create aliases using dns to point to the correct
servers in each environment and use that alias. Then once the alias is
used as the seed it will use the correct values configured in the
replica set for the rest of the communications and health monitoring.

mo

unread,
Apr 9, 2012, 11:13:24 AM4/9/12
to mongodb-csharp
Thanks. That makes a lot of sense!

mo

unread,
Jun 26, 2012, 10:24:57 AM6/26/12
to mongodb...@googlegroups.com
Hello again, sorry to dredge this up. I just realised that, when I said "it seems to work fine", I was not being completely accurate. My client code has a piece that catches mongo connection exceptions and retries the connection ten times before giving up. I noticed that it actually never succeeds the first time, and only on the second attempt does it get connected. It seems, oddly, when the connection string contains any of the following seed lists...

"mongodb://localTestingServer1/"
"mongodb://localTestingServer1,localTestingServer2,localTestingServer3/"
"mongodb://productionReplicasetServer1,productionReplicasetServer2,productionReplicasetServer3,localTestingServer1,localTestingServer2,localTestingServer3/"

...it works but when it contains...

"mongodb://productionReplicasetServer1,productionReplicasetServer2,productionReplicasetServer3,localTestingServer1/" (without local 2 or 3)

...I get the following exception the first time, then the second attempt works, presumably because by then the collection has already been modified and isn't being modified during enumeration.

System.InvalidOperationException, "Collection was modified; enumeration operation may not execute."
source: mscorlib
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at System.Collections.Generic.List`1.Enumerator.MoveNext()
at MongoDB.Driver.MongoServer.VerifyInstances(List`1 instanceAddresses)
at MongoDB.Driver.MongoServerInstance.VerifyState(MongoConnection connection)
at MongoDB.Driver.MongoServerInstance.Connect(Boolean slaveOk)
at MongoDB.Driver.Internal.ReplicaSetConnector.ConnectWorkItem(Object argsObject)
Target site: Void ThrowInvalidOperationException(System.ExceptionResource)

For me, a suitable workaround obviously is to use the longest seed list, the one containing all three production and all three local testing servers. It does seem a bit like a bug to me, though.

Any thoughts?

Regards,
Mo

craiggwilson

unread,
Jun 26, 2012, 5:18:03 PM6/26/12
to mongodb...@googlegroups.com
It is definitely a bug.  We are working on the connection code right now to clear some of this up and other stuff as well.  Version 1.5 should fix this, which should be out in a couple of weeks.
Reply all
Reply to author
Forward
0 new messages