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

Create Causal Consistency code samples for MongoDB 3.6 page

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.0.3
    • Affects Version/s: None
    • Component/s: None
    • Labels:

      Please provide the equivalent Node code for the following Java example:

      Causal Consistency

      // 2. Tunable consistency controls
      String connectionString = "mongodb://localhost/?readPreference=secondaryPreferred";
       
      MongoClient client = new MongoClient(new MongoClientURI(connectionString);
       
      MongoDatabase database = client.getDatabase("myDatabase");
      MongoCollection<Document> collection = database.getCollection("myCollection");
       
      // Start client session, which is causally consistent by default
      try (ClientSession session = client.startSession(ClientSessionOptions.builder().build())) {
        //Run causally related operations within the session
        collection.insertOne(session, ...);
        collection.updateOne(session, ...);
       
        try (MongoCursor<Document> cursor = collection.find(session).filter(...).iterator()) {
          while (cursor.hasNext()) {
            Document cur = cursor.next();
          }
        }
      }
      

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

              Created:
              Updated:
              Resolved: