Uploaded image for project: 'Drivers'
  1. Drivers
  2. DRIVERS-2181

Snapshot Query Examples for the Manual

    • Type: Icon: Task Task
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Component/s: Docs Examples
    • None
    • Needed
    • Hide

      NA

      Show
      NA
    • $i18n.getText("admin.common.words.hide")
      Key Status/Resolution FixVersion
      CDRIVER-4295 Fixed 1.24.0
      CXX-2454 Done 3.8.0
      CSHARP-4055 Backlog
      GODRIVER-2310 Done
      JAVA-5422 Backlog
      NODE-6103 Backlog
      MOTOR-894 Fixed 3.0
      PYTHON-3127 Fixed 4.1
      PHPLIB-789 Fixed 1.13.0-beta1, 1.13.0
      RUBY-2909 Fixed 2.18.0
      RUST-1187 Backlog
      SWIFT-1494 Won't Do
      $i18n.getText("admin.common.words.show")
      #scriptField, #scriptField *{ border: 1px solid black; } #scriptField{ border-collapse: collapse; } #scriptField td { text-align: center; /* Center-align text in table cells */ } #scriptField td.key { text-align: left; /* Left-align text in the Key column */ } #scriptField a { text-decoration: none; /* Remove underlines from links */ border: none; /* Remove border from links */ } /* Add green background color to cells with FixVersion */ #scriptField td.hasFixVersion { background-color: #00FF00; /* Green color code */ } /* Center-align the first row headers */ #scriptField th { text-align: center; } Key Status/Resolution FixVersion CDRIVER-4295 Fixed 1.24.0 CXX-2454 Done 3.8.0 CSHARP-4055 Backlog GODRIVER-2310 Done JAVA-5422 Backlog NODE-6103 Backlog MOTOR-894 Fixed 3.0 PYTHON-3127 Fixed 4.1 PHPLIB-789 Fixed 1.13.0-beta1, 1.13.0 RUBY-2909 Fixed 2.18.0 RUST-1187 Backlog SWIFT-1494 Won't Do

      The server documentation team would like to add driver examples for snapshot queries. I've mocked up the examples we want to use in Python. I've also included the delineation we'd like to use:

      // Start Snapshot Query Example 1
      
      client = MongoClient()
      db = client.pets
      with client.start_session(snapshot=True) as s:
         adoptablePetsCount = db.cats.aggregate(
             [ { "$match": { "adoptable": true } }, { "$count": "adoptableCatsCount" } ],
             session=s
         ).next()["adoptableCatsCount"]
      
         adoptablePetsCount += db.dogs.aggregate(
             [ { "$match": { "adoptable": True} }, { "$count": "adoptableDogsCount" } ],
             session=s
         ).next()["adoptableDogsCount"]
      
      print(adoptablePetsCount)
      
      // End Snapshot Query Example 1
      
      // Start Snapshot Query Example 2
      client = MongoClient()
      db = client.retail
      with client.start_session(snapshot=True) as s:
        total = db.sales.aggregate( [
           {
              $match: {
                 $expr: {
                    $gt: [
                       "$saleDate",
                       {
                          $dateSubtract: {
                             startDate: "$$NOW",
                             unit: "day",
                             amount: 1
                          }
                       }
                    ]
                  }
               }
           },
           { $count: "totalDailySales" }
        ], session=s
        ).next()["totalDailySales"]
      
      // End Snapshot Query Example 2
      

      The examples will appear on this page: https://docs-mongodbcom-staging.corp.mongodb.com/docs/docsworker-xlarge/DOCS-15065/tutorial/long-running-queries/

      Let me know if you need any more information. Thank you for your help!

            Assignee:
            Unassigned Unassigned
            Reporter:
            jeffrey.allen@mongodb.com Jeffrey Allen
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: