[CSHARP-1313] Combing Inc, silent fail Created: 13/Jun/15  Updated: 13/Jun/15  Resolved: 13/Jun/15

Status: Closed
Project: C# Driver
Component/s: API
Affects Version/s: 2.0.1
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Dwayne Bull Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

CSharp, mono and .net



 Description   

Applying:
Builders<T>.Update.Inc( "id",1).Inc("id",-1)
To:

{id:0}

Result:

{id:-1}

Combining Inc doesn't seem to work, it will overwrite the last inc on the same field, this is made more troublesome by the inability to update a collection with a BsonDocument as the update so you can't get round this.

There seems to be no error and no way of querying the UpdateDefinition to see if an existing Inc for the field exists.



 Comments   
Comment by Dwayne Bull [ 13/Jun/15 ]

Fair enough.
I didn't realise you could cast a BsonDocument to an UpdateDefinition, that will solve my issue with a bit of work, thanks.

Comment by Craig Wilson [ 13/Jun/15 ]

While there is a remote possibility we could do what you are asking for, I'm going to mark this as won't fix. It would be surprising for this to happen for current users of this driver as well as other drivers.

UpdateDefinition is implicitly convertible to a BsonDocument, so you certainly can do what you are asking for. See the documentation here: http://mongodb.github.io/mongo-csharp-driver/2.0/reference/driver/definitions/#updates

Comment by Dwayne Bull [ 13/Jun/15 ]

I was hoping for the numeric inc to be taken care of client side, so the resulting combined inc would be passed to the server.
On another note, it would be good the update methods of IMongoCollection accepted a BsonDocument as well as UpdateDefinition so updates could be done "by hand"

Comment by Craig Wilson [ 13/Jun/15 ]

Hi Dwayne,

This is not supported in MongoDB. Overwriting or throwing is our only option. We opted for overwriting. Also, realize that this incrementing is taking place server side. We are constructing the update document

{ $inc: { id: 1 } }

and sending it to the server. Since duplicated fields are not allowed, we simply can't do what you are wanting.

Perhaps you could elaborate as to what you need is here and maybe we can figure out another way to handle it.

Craig

Comment by Dwayne Bull [ 13/Jun/15 ]

Edit: If would be good if the result was:

{id:0}
Generated at Wed Feb 07 21:39:15 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.