Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-1937

Causal Consistency issue

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Works as Designed
    • Affects Version/s: 3.2.3
    • Fix Version/s: None
    • Component/s: core
    • Labels:
      None
    • MongoDB Version:
      3.6.3

      Description

      The native driver doesn't support Causal Consistency(Real Time Order) as expected.

       

       

      var db = client.db('test');
       var largeObj = {};
       for(var i = 0; i < 10000; i++){
       largeObj['aaaaaaaaaaaaaaaa' + i] = Math.random();
       }
      var session = client.startSession();
      var v = Date.now();
      console.log('init v', v);
      var collection = db.collection('test');
      //OP1
      collection.updateOne({_id: 1}, {$set: Object.assign({v: v + 1}, largeObj)}, {session, upsert: true}, function(){ console.log(new Date(), 'a'); });
      //OP2
      collection.findOne({_id: 1}, {projection: {v: 1}, session}, function(err, result){ console.log(new Date(), err, result)});
      //OP3
      collection.updateOne({_id: 1}, {$set: {v: v+ 2}}, {session}, function(){ console.log(new Date(), 'b'); });
      //OP4
      collection.findOne({_id: 1}, {projection: {v: 1}, session}, function(err, result){ console.log(new Date(), err, result)});
      setTimeout( () => {
       db.collection('test').findOne({_id: 1}, {projection: {v: 1}, session}, console.log);
       }, 2000);
      
      

       

       

      Expect execute order: OP1=>OP2=>OP3=>OP4

      Get: OP2=>OP4=>OP1=>OP3

       

      Versions:

      MongoDB@3.6.3

      native driver@3.2.3

      NodeJs@v8.9.3

        Attachments

          Activity

            People

            Assignee:
            daniel.aprahamian Daniel Aprahamian (Inactive)
            Reporter:
            tong20078 tongzhilian
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: