[DOCS-15093] Fix error in expected output for $setWindowFields example Created: 04/Feb/22  Updated: 30/Oct/23  Resolved: 07/Feb/22

Status: Closed
Project: Documentation
Component/s: Server
Affects Version/s: None
Fix Version/s: Server_Docs_20231030

Type: Task Priority: Minor - P4
Reporter: Robert Stam Assignee: Unassigned
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:
Days since reply: 2 years, 5 days ago

 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 >



 Comments   
Comment by Robert Stam [ 04/Feb/22 ]

Actually... looking more closely it looks like the error was in my failing test in the C# driver.

Looks like the documentation is actually correct.

Sorry for the false alarm. Take a quick look and verify but this ticket should probably be closed as no fix needed.

Generated at Thu Feb 08 08:12:00 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.