[CSHARP-805] MongoDB 2.4.5 Win7 64bit fails to insert via standard csharp-driver 1.8.2 Created: 21/Aug/13 Updated: 22/Aug/13 Resolved: 21/Aug/13 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | 1.8.2 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Rob Finneran | Assignee: | Sridhar Nanjundeswaran |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Windows 7 64 bit MongoDB 2.4.5 |
||
| Description |
|
Hi Sorry if this is a rookie mistake but I could net get inserts or updates to work. However, inserts using mongo.exe command line works just fine. Here is my code, no errors returned, just DocumentsAffected == 0 Please Help!!! using System; namespace MyProjectNamespace.MongoConsoleApp public string Name { get; set; } } class Program var server = client.GetServer(); using (database.RequestStart()) if (result.ErrorMessage != null) { Console.WriteLine("mongodb: {0} ", result.ErrorMessage); ", result.LastErrorMessage); Console.ReadLine(); |
| Comments |
| Comment by Rob Finneran [ 22/Aug/13 ] |
|
Thanks Sridhar and Craig for helping me to understand this better. I really appreciate your help. |
| Comment by Craig Wilson [ 21/Aug/13 ] |
|
Sridhar is correct that we will thrown an Exception if you have a WriteConcern other than Unacknowledged. The type of exception thrown will be a WriteConcernException. Currently, there are no timeouts for writes. However, if you have set a socket timeout and it expires, you will received a System.IO.SocketException. Regarding the blocking, it most definitely is blocking given your code above. Not sure why you think it isn't other than it just goes really fast. You will get a WriteConcernResult back. If you didn't get an exception, then everything happened successfully and there really isn't a need to check that for inserts. However, as Sridhar said, this same result is used for Updates in which the number of documents affected will have a value. Also, just to point this out, your connection string has w=1 and journal=true. When you explicitly pass in WriteConcern.Acknowledged, you are overriding the connection string settings. |
| Comment by Sridhar Nanjundeswaran [ 21/Aug/13 ] |
|
GetLastErrorResults.DocumentAffected (n in the result of the getLastError command) is only set for updates. So if you issue an update you can then use DocumentsAffected |
| Comment by Rob Finneran [ 21/Aug/13 ] |
|
Hi Craig, Thanks for all your hard work! I was mistaken in that the record was not written. It was, so this is good news. However, I still think there is a bug! The WriteConcern.Acknowledged feature would not be of much use if the client program was not informed of the acknowledgement. DocumentsAffected and getLastError should tell us if the updated succeeded or not. My client code should be able to retry or determine another course of action (like to quit the program) I changed my connection string to: string connectionString = "mongodb://localhost/test?w=1&journal=true"; and my insert statement to: collection.Insert(entity, WriteConcern.Acknowledged); You would think that the C# driver should block (according to my reading of the mongodb docs, it should) and it would block until the write was successful or timed out (or some other error). I'm not sure how easy it is to test this behavior, but let us assume for the moment it does. If it did block, the sending thread should get some result back, or at least could query for the result. Is it possible that the code is ignoring the WriteConcern.Acknowledged feature or the w=1;journel=true? I guess I should start looking into the source code to see what is actually happening. Do you think this is a bug, a new feature request, or just a differing opinion on the right design? Thanks!!! |
| Comment by Craig Wilson [ 21/Aug/13 ] |
|
Did you actually check the database to see if your documents were there? I ran your program above and I also get documentsAffected = 0, but the documents exist in the database. I can't find any documentation for whether or not this should be 1 or 0. However, when I run this in the shell and explicitly run getLastError after I perform an insert, 0 is returned for 'n', which is the number of documents affected. If you'd like to file a server bug, feel free, but this is not a bug in the .NET driver as we just report what the server tells us. |