File tree Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -1327,13 +1327,14 @@ describe("firestore", () => {
13271327describe ( "firestore-pipelines" , ( ) => {
13281328 const {
13291329 Firestore,
1330+ Timestamp,
13301331 collection,
13311332 doc,
13321333 getFirestore,
13331334 orderBy,
13341335 query,
13351336 setDoc,
1336- startAt
1337+ startAt,
13371338 } = require ( "firebase/firestore" )
13381339 const {
13391340 Pipeline,
@@ -1362,6 +1363,20 @@ describe("firestore-pipelines", () => {
13621363 db = getFirestore ( app , "enterprise" ) ;
13631364 } ) ;
13641365
1366+ async function stagesExpressionsExample ( ) {
1367+ // [START stages_expressions_example]
1368+ const trailing30Days = constant ( Timestamp . now ( ) . toMillis ( ) )
1369+ . unixMillisToTimestamp ( )
1370+ . timestampSubtract ( "day" , 30 ) ;
1371+ const snapshot = await execute ( db . pipeline ( )
1372+ . collection ( "productViews" )
1373+ . where ( field ( "viewedAt" ) . greaterThan ( trailing30Days ) )
1374+ . aggregate ( field ( "productId" ) . countDistinct ( ) . as ( "uniqueProductViews" ) )
1375+ ) ;
1376+ // [END stages_expressions_example]
1377+ console . log ( snapshot ) ;
1378+ }
1379+
13651380 async function basicRead ( ) {
13661381 // [START basic_read]
13671382 const readDataPipeline = db . pipeline ( )
Original file line number Diff line number Diff line change @@ -5,7 +5,8 @@ const { expect } = require('chai');
55
66describe ( "firestore-pipelines" , ( ) => {
77 const {
8- Firestore
8+ Firestore,
9+ Timestamp
910 } = require ( "@google-cloud/firestore" )
1011 const {
1112 Pipeline,
@@ -31,6 +32,20 @@ describe("firestore-pipelines", () => {
3132 } ) ;
3233 } ) ;
3334
35+ async function stagesExpressionsExample ( ) {
36+ // [START stages_expressions_example]
37+ const trailing30Days = constant ( Timestamp . now ( ) . toMillis ( ) )
38+ . unixMillisToTimestamp ( )
39+ . timestampSubtract ( "day" , 30 ) ;
40+ const snapshot = await db . pipeline ( )
41+ . collection ( "productViews" )
42+ . where ( field ( "viewedAt" ) . greaterThan ( trailing30Days ) )
43+ . aggregate ( field ( "productId" ) . countDistinct ( ) . as ( "uniqueProductViews" ) )
44+ . execute ( ) ;
45+ // [END stages_expressions_example]
46+ console . log ( snapshot ) ;
47+ }
48+
3449 async function basicRead ( ) {
3550 // [START basic_read]
3651 const readDataPipeline = db . pipeline ( )
You can’t perform that action at this time.
0 commit comments