[CSHARP-4473] Cannot resolve method "UpdateOneAsync" Created: 05/Jan/23  Updated: 27/Oct/23  Resolved: 05/Jan/23

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

Type: Bug Priority: Major - P3
Reporter: Daniel Martin Assignee: Dmitry Lukyanov (Inactive)
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Summary

I am trying to Update / Replace an document with the C# MongoDB.Driver.

 

``` csharp

var Collection = DbContext.DbSet<MyEntity>();
var filter = Builders<MyEntity>.Filter.Eq(x => x.Id, entity.Id);
var update = Builders<MyEntity>.Update.Set(e => e.Name, entity.Name);
await Collection.UpdateOneAsync(filter, update, cancellationToken);
```

 

but whichever overload I am using, I get the error

 

```

Cannot resolve method 'UpdateOneAsync(MongoDB.Driver.FilterDefinition<MyEntity>, MongoDB.Driver.UpdateDefinition<MyEntity>, System.Threading.CancellationToken)', candidates are: System.Threading.Tasks.Task<MongoDB.Driver.UpdateResult> UpdateOneAsync(MongoDB.Driver.FilterDefinition<MyEntity>, MongoDB.Driver.UpdateDefinition<MyEntity>, MongoDB.Driver.UpdateOptions, System.Threading.CancellationToken) (in interface IMongoCollection<MyEntity>) System.Threading.Tasks.Task<MongoDB.Driver.UpdateResult> UpdateOneAsync(MongoDB.Driver.IClientSessionHandle, MongoDB.Driver.FilterDefinition<MyEntity>, MongoDB.Driver.UpdateDefinition<MyEntity>, MongoDB.Driver.UpdateOptions, System.Threading.CancellationToken) (in interface IMongoCollection<MyEntity>) System.Threading.Tasks.Task<MongoDB.Driver.UpdateResult> UpdateOneAsync<MyEntity>(this MongoDB.Driver.IMongoCollection<MyEntity>, MongoDB.Driver.IClientSessionHandle, System.Linq.Expressions.Expression<System.Func<MyEntity,bool>>, MongoDB.Driver.UpdateDefinition<MyEntity>, MongoDB.Driver.UpdateOptions, System.Threading.CancellationToken) (in class IMongoCollectionExtensions) System.Threading.Tasks.Task<MongoDB.Driver.UpdateResult> UpdateOneAsync<MyEntity>(this MongoDB.Driver.IMongoCollection<MyEntity>, System.Linq.Expressions.Expression<System.Func<MyEntity,bool>>, MongoDB.Driver.UpdateDefinition<MyEntity>, MongoDB.Driver.UpdateOptions, System.Threading.CancellationToken) (in class IMongoCollectionExtensions)

```

 

I guess this is a bug, but I am not sure if I am the one who does something wrong here.

Other methods like "FindAsync", "InsertOneAsync", etc work as expected

MongoDB.Driver: 2.18.0



 Comments   
Comment by Daniel Martin [ 05/Jan/23 ]

Yes this works! Thanks a lot! 

Comment by Dmitry Lukyanov (Inactive) [ 05/Jan/23 ]

Hey daniel@zookeeper.app,

as I can see, your issue is related to the fact that you're trying to call UpdateOneAsync overload that doesn't exist. If you want to avoid the 3rd argument which is "UpdateOptions" and still using cancellationToken, specify cancellationToken argument name explicitly like:

    .UpdateOneAsync(filter, update, cancellationToken: CancellationToken.None)

Generated at Wed Feb 07 21:48:20 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.