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

Causal Consistency issue

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.2.3
    • Component/s: Core

      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

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

              Created:
              Updated:
              Resolved: