Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-15093

Fix error in expected output for $setWindowFields example

    XMLWordPrintableJSON

Details

    • Icon: Task Task
    • Resolution: Gone away
    • Icon: Minor - P4 Minor - P4
    • Server_Docs_20231030
    • None
    • Server
    • None

    Description

      In this example:

      https://docs.mongodb.com/manual/reference/operator/aggregation/setWindowFields/#use-a-time-range-window-with-a-negative-upper-bound

      the output is wrong (on the second line for _id  0). It should be:

      MongoDB Enterprise > db.cakeSales.aggregate( [
      ...    {
      ...       $setWindowFields: {
      ...          partitionBy: "$State",
      ...          sortBy: { OrderDate: 1 },
      ...          output: {
      ...             RecentOrders: {
      ...                $push: "$OrderDate",
      ...                window: {
      ...                   range: [ "unbounded", -10 ],
      ...                   unit: "month"
      ...                }
      ...             }
      ...          }
      ...       }
      ...    }
      ... ] )
      { "_id" : 4, "Type" : "strawberry", "OrderDate" : ISODate("2019-05-18T16:09:01Z"), "State" : "CA", "Price" : 41, "Quantity" : 162, "RecentOrders" : [ ] }
      { "_id" : 0, "Type" : "chocolate", "OrderDate" : ISODate("2020-05-18T14:10:30Z"), "State" : "CA", "Price" : 13, "Quantity" : 120, "RecentOrders" : [ ISODate("2019-05-18T16:09:01Z") ] }
      { "_id" : 2, "Type" : "vanilla", "OrderDate" : ISODate("2021-01-11T06:31:15Z"), "State" : "CA", "Price" : 12, "Quantity" : 145, "RecentOrders" : [ ISODate("2019-05-18T16:09:01Z") ] }
      { "_id" : 5, "Type" : "strawberry", "OrderDate" : ISODate("2019-01-08T06:12:03Z"), "State" : "WA", "Price" : 43, "Quantity" : 134, "RecentOrders" : [ ] }
      { "_id" : 3, "Type" : "vanilla", "OrderDate" : ISODate("2020-02-08T13:13:23Z"), "State" : "WA", "Price" : 13, "Quantity" : 104, "RecentOrders" : [ ISODate("2019-01-08T06:12:03Z") ] }
      { "_id" : 1, "Type" : "chocolate", "OrderDate" : ISODate("2021-03-20T11:30:05Z"), "State" : "WA", "Price" : 14, "Quantity" : 140, "RecentOrders" : [ ISODate("2019-01-08T06:12:03Z"), ISODate("2020-02-08T13:13:23Z") ] }
      MongoDB Enterprise >
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            robert@mongodb.com Robert Stam
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              2 years, 5 days ago