Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-1857

FindOneAndReplace or ReplaceOne is not working sometime

    • Type: Icon: Task Task
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.2.4, 2.4
    • Component/s: Operations
    • Environment:
      Windows Server 2016, Asp.net,

      public async Task SomeWork()
              {
                  Debug.WriteLine("SomeWork for User : " + Context.User.Identity.Name);
                  var userProfile = await UserProfileCollection.Find(u => u._id == Context.User.Identity.Name).FirstOrDefaultAsync();
      
                  userProfile.SuccessfullConnect = true; // currently false
                  var up = await UserProfileCollection.FindOneAndReplaceAsync(u => u._id == userProfile._id, userProfile);
                  Debug.WriteLine(ObjectDumper.Dump(userProfile));
                  Debug.WriteLine(ObjectDumper.Dump(up));
                  Debug.WriteLine("Saved SomeWork for User : " + Context.User.Identity.Name);
              }
      

      Below is the debug output. My document is not getting replaced. Check SuccessfullConnect variable it is still false. I checked on server also document is not replaced. And sometime its working and sometime its not working.

      SomeWork for User : +919933221101
      {TestSignalR_Server.Models.UserProfile}
        _id: "+919933221101"
        ...
        SuccessfullConnect: True
        ...
      
      {TestSignalR_Server.Models.UserProfile}
        _id: "+919933221101"
        ...
        SuccessfullConnect: False
        ...
      
      Saved SomeWork for User : +919933221101
      

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            KalpeshChheda Kalpesh Chheda [X]
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: