RobIII
2012-12-05 14:15:22 UTC
I have a .Net WCF service which acts as an interface between our software
and MongoDB using MongoRepository <http://mongorepository.codeplex.com/>.
Since I have updated to the 1.7.0 driver version I get an "WriteConcern
detected an error E11000 duplicate key error index..." error when I call
the Save method on documents that, indeed, have a unique index.
Let me give you the full story: first, my object (in simplified form, PHP
notation):
object(NIDEntry)#40 (12) {
["Id"]=>
string(24) "5069e318ce93af04d8aa582e"
["Name"]=>
string(3) "Foo"
["AssociatedNumbers"]=>
array(1) {
[0]=>
object(NIDPhoneNumber)#51 (6) {
["CountryCode"]=>
string(4) "0031"
["AreaCode"]=>
string(4) "0987"
["SubscriberNumber"]=>
string(6) "123456"
["PublishType"]=>
string(1) "p"
["NumberType"]=>
string(1) "p"
["NIDStatus"]=>
NULL
}
}
["CreateDate"]=>
string(24) "2012-10-01T18:38:16.171Z"
}
These documents are stored in an NIDEntries collection. This collection has
2 indexes; one for _id (obviously) and one for CountryCode + AreaCode +
SubscriberNumber. I have checked, double-checked and triple-checked that
this is the only document containing this number (0031 0987 123456). Next,
I simply fetch the object using the FindOneByIdAs<NIDEntry>() method. Then
I change, for example, only the name ("Foo" => "FooTest") and issue a
.Save(). This results in the "WriteConcern detected an error E11000
duplicate key error
index NID.NIDEntry.$AssociatedNumbers.SubscriberNumber_1_AssociatedNumbers.AreaCode_1_AssociatedNumbers.CountryCode_1
dup key: { : "123456", : "0987", : "0031" }" exception.
Now here's the thing:
We have a DTAP<http://en.wikipedia.org/wiki/Development,_testing,_acceptance_and_production>environment; all 4 have their own copy of the WCF service.
*D* and *T* connect to (say) *mongo-A* (2.2.0) to a database (say) *NID_D*or
*NID_T*. The *A* and *P* servers also run the WCF service; both connecting
to *mongo-B* (2.2.0) to a database (say) *NID_A* and *NID_P*. I have
illustrated this in the diagram below (fear my paint skills):
<Loading Image...
>
Remember that each server/service connects to it's own database (NID_D,
NID_T, NID_A, NID_P respectively) which is not in the diagram. I have
checked, double checked and triple checked that all servers are running the
same WCF service version. Each of them is using the 1.7 version of the
mongocsharpdriver. Calling the .Save() method on D, T, and A work fine for
updating. Calling the .Save() method on P fails with the exception.
I have ruled out the following:
- It can't be the mongo server; as both A and B are 2.2.0 (on linux) and D,
T and A are fine updating existing documents, P is not.
- It can't be the mongocsharp driver, as D, T and A are fine updating
existing documents, P is not.
- There's no difference, except for names, IP's and database names, in
the connectionstrings for each of the DTAP servers.
- The document is the *only *document containing the unique (combination
of) field(s) value(s). I am doing an "update" using the .Save()<http://www.mongodb.org/display/DOCS/CSharp+Driver+Quickstart#CSharpDriverQuickstart-Saveadocument>method (which is abstracted to
.Update()<http://mongorepository.codeplex.com/SourceControl/changeset/view/20996#457813>by the MongoRepository).
- The E11000 exception would be explained when doing an insert of a new
document; however: there's no insert being done but an update (upsert if
you will).
I have rolled back the P server to the previous version which relies on MongoRepository
1.4.0 <http://mongorepository.codeplex.com/SourceControl/list/changesets>which relies on the 1.6.1 driver (and
safe=true in the connectionstring). The service is then fine with updating
the document. When rolling out the new version of the service (which has no
functional changes at all except for the dependency on MongoRepository
1.4.1 which, in turn, relies on the 1.7 driver) the P server fails. The
changes in 1.4.1 are minimal<http://mongorepository.codeplex.com/SourceControl/changeset/20995>.
What I can't explain is why this *works fine* on D, T and A but *not P*. The
services are "deployed" using the "XCopy deployment" style; it's just a
simple directory containing an .exe, and some DLL's. The WCF services, by
the way, are self hosted (not in IIS) and run as Windows service.
In an act of insanity I have run the new version of the WCF service locally
on my development machine which I'm sure is running the v1.7 driver and let
it connect to "*mongo-B*" to the *NID_P* database. Next, I retrieved the
document, updated the "name" property and issued the same .Save(). Lo and
behold: This works fine!?!? So the problem isn't caused by (say) a
"confused mongodb" server or "damaged collection"-file or something. Would
this have caused the same exception one of these things might be the case
but it turns out it isn't.
There are 2 things I haven't done (yet) to rule stuff out:
1. There's another (XCopy deployed) service running using the 1.6.1
driver on *only *the *P* server (not on the other three). However:
- a) this *shouldn't* interfere (why would windows use the 1.6.1
driver from the other service's directory for example?)
- b) I have stopped this service to rule out that somehow things were
getting their wires crossed (this did not help)
- c) why is it that 1.6.1 or 1.7 run fine on D, T and A then?
2. Rebooting the server
My question is: what could be causing this? What would be a good way to
troubleshoot / debug this problem? Any help is appreciated.
and MongoDB using MongoRepository <http://mongorepository.codeplex.com/>.
Since I have updated to the 1.7.0 driver version I get an "WriteConcern
detected an error E11000 duplicate key error index..." error when I call
the Save method on documents that, indeed, have a unique index.
Let me give you the full story: first, my object (in simplified form, PHP
notation):
object(NIDEntry)#40 (12) {
["Id"]=>
string(24) "5069e318ce93af04d8aa582e"
["Name"]=>
string(3) "Foo"
["AssociatedNumbers"]=>
array(1) {
[0]=>
object(NIDPhoneNumber)#51 (6) {
["CountryCode"]=>
string(4) "0031"
["AreaCode"]=>
string(4) "0987"
["SubscriberNumber"]=>
string(6) "123456"
["PublishType"]=>
string(1) "p"
["NumberType"]=>
string(1) "p"
["NIDStatus"]=>
NULL
}
}
["CreateDate"]=>
string(24) "2012-10-01T18:38:16.171Z"
}
These documents are stored in an NIDEntries collection. This collection has
2 indexes; one for _id (obviously) and one for CountryCode + AreaCode +
SubscriberNumber. I have checked, double-checked and triple-checked that
this is the only document containing this number (0031 0987 123456). Next,
I simply fetch the object using the FindOneByIdAs<NIDEntry>() method. Then
I change, for example, only the name ("Foo" => "FooTest") and issue a
.Save(). This results in the "WriteConcern detected an error E11000
duplicate key error
index NID.NIDEntry.$AssociatedNumbers.SubscriberNumber_1_AssociatedNumbers.AreaCode_1_AssociatedNumbers.CountryCode_1
dup key: { : "123456", : "0987", : "0031" }" exception.
Now here's the thing:
We have a DTAP<http://en.wikipedia.org/wiki/Development,_testing,_acceptance_and_production>environment; all 4 have their own copy of the WCF service.
*D* and *T* connect to (say) *mongo-A* (2.2.0) to a database (say) *NID_D*or
*NID_T*. The *A* and *P* servers also run the WCF service; both connecting
to *mongo-B* (2.2.0) to a database (say) *NID_A* and *NID_P*. I have
illustrated this in the diagram below (fear my paint skills):
<Loading Image...
Remember that each server/service connects to it's own database (NID_D,
NID_T, NID_A, NID_P respectively) which is not in the diagram. I have
checked, double checked and triple checked that all servers are running the
same WCF service version. Each of them is using the 1.7 version of the
mongocsharpdriver. Calling the .Save() method on D, T, and A work fine for
updating. Calling the .Save() method on P fails with the exception.
I have ruled out the following:
- It can't be the mongo server; as both A and B are 2.2.0 (on linux) and D,
T and A are fine updating existing documents, P is not.
- It can't be the mongocsharp driver, as D, T and A are fine updating
existing documents, P is not.
- There's no difference, except for names, IP's and database names, in
the connectionstrings for each of the DTAP servers.
- The document is the *only *document containing the unique (combination
of) field(s) value(s). I am doing an "update" using the .Save()<http://www.mongodb.org/display/DOCS/CSharp+Driver+Quickstart#CSharpDriverQuickstart-Saveadocument>method (which is abstracted to
.Update()<http://mongorepository.codeplex.com/SourceControl/changeset/view/20996#457813>by the MongoRepository).
- The E11000 exception would be explained when doing an insert of a new
document; however: there's no insert being done but an update (upsert if
you will).
I have rolled back the P server to the previous version which relies on MongoRepository
1.4.0 <http://mongorepository.codeplex.com/SourceControl/list/changesets>which relies on the 1.6.1 driver (and
safe=true in the connectionstring). The service is then fine with updating
the document. When rolling out the new version of the service (which has no
functional changes at all except for the dependency on MongoRepository
1.4.1 which, in turn, relies on the 1.7 driver) the P server fails. The
changes in 1.4.1 are minimal<http://mongorepository.codeplex.com/SourceControl/changeset/20995>.
What I can't explain is why this *works fine* on D, T and A but *not P*. The
services are "deployed" using the "XCopy deployment" style; it's just a
simple directory containing an .exe, and some DLL's. The WCF services, by
the way, are self hosted (not in IIS) and run as Windows service.
In an act of insanity I have run the new version of the WCF service locally
on my development machine which I'm sure is running the v1.7 driver and let
it connect to "*mongo-B*" to the *NID_P* database. Next, I retrieved the
document, updated the "name" property and issued the same .Save(). Lo and
behold: This works fine!?!? So the problem isn't caused by (say) a
"confused mongodb" server or "damaged collection"-file or something. Would
this have caused the same exception one of these things might be the case
but it turns out it isn't.
There are 2 things I haven't done (yet) to rule stuff out:
1. There's another (XCopy deployed) service running using the 1.6.1
driver on *only *the *P* server (not on the other three). However:
- a) this *shouldn't* interfere (why would windows use the 1.6.1
driver from the other service's directory for example?)
- b) I have stopped this service to rule out that somehow things were
getting their wires crossed (this did not help)
- c) why is it that 1.6.1 or 1.7 run fine on D, T and A then?
2. Rebooting the server
My question is: what could be causing this? What would be a good way to
troubleshoot / debug this problem? Any help is appreciated.
--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongodb-user-/***@public.gmane.org
To unsubscribe from this group, send email to
mongodb-user+unsubscribe-/***@public.gmane.org
See also the IRC channel -- freenode.net#mongodb
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongodb-user-/***@public.gmane.org
To unsubscribe from this group, send email to
mongodb-user+unsubscribe-/***@public.gmane.org
See also the IRC channel -- freenode.net#mongodb