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

FindOneAndReplace or ReplaceOne is not working sometime

    XMLWordPrintableJSON

Details

    • Icon: Task Task
    • Resolution: Works as Designed
    • Icon: Major - P3 Major - P3
    • None
    • 2.2.4, 2.4
    • Operations
    • Windows Server 2016, Asp.net,

    Description

      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
      

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: