Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add snippets for OR queries #364

Merged
merged 11 commits into from
Jun 1, 2023
2 changes: 1 addition & 1 deletion auth/functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"compile": "cp ../../tsconfig.template.json ./tsconfig.json && tsc"
},
"dependencies": {
"firebase-admin": "^11.8.0",
"firebase-admin": "^11.9.0",
"firebase-functions": "^4.4.0"
}
}
2 changes: 1 addition & 1 deletion auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"dependencies": {
"express": "^4.18.2",
"firebase-admin": "^11.8.0",
"firebase-admin": "^11.9.0",
"firebase-functions": "^4.4.0"
}
}
2 changes: 1 addition & 1 deletion config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"compile": "cp ../tsconfig.template.json ./tsconfig.json && tsc"
},
"dependencies": {
"firebase-admin": "^11.8.0"
"firebase-admin": "^11.9.0"
},
"author": "",
"license": "ISC"
Expand Down
2 changes: 1 addition & 1 deletion database/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"compile": "cp ../tsconfig.template.json ./tsconfig.json && tsc"
},
"dependencies": {
"firebase-admin": "^11.8.0"
"firebase-admin": "^11.9.0"
}
}
2 changes: 1 addition & 1 deletion firebaseapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"compile": "cp ../tsconfig.template.json ./tsconfig.json && tsc"
},
"dependencies": {
"firebase-admin": "^11.8.0"
"firebase-admin": "^11.9.0"
}
}
2 changes: 1 addition & 1 deletion firestore/extend-with-functions/functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"dependencies": {
"@google-cloud/firestore": "^6.6.0",
"firebase-admin": "^11.8.0",
"firebase-admin": "^11.9.0",
"firebase-functions": "^4.4.0"
}
}
41 changes: 40 additions & 1 deletion firestore/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const debug = require('debug')('firestore-snippets-node');

// [START firestore_deps]
const { initializeApp, applicationDefault, cert } = require('firebase-admin/app');
const { getFirestore, Timestamp, FieldValue } = require('firebase-admin/firestore');
const { getFirestore, Timestamp, FieldValue, Filter } = require('firebase-admin/firestore');
// [END firestore_deps]


Expand Down Expand Up @@ -647,6 +647,41 @@ async function inQueries(db) {
console.log('Exactly One Coast get: ', exactlyOneCoast);
}

/**
* Demonstrate OR queries
*
* @param {FirebaseFirestore.Firestore} db
*/
async function orQueries(db) {
const citiesRef = db.collection('cities');

// [START firestore_query_or]
const bigCities = await citiesRef
.where(
Filter.or(
Filter.where('capital', '==', true),
Filter.where('population', '>=', 1000000)
)
)
.get();
// [END firestore_query_or]

// [START firestore_query_or_compound]
const bigCitiesInCalifornia = await citiesRef
.where('state', '==', 'CA')
.where(
Filter.or(
Filter.where('capital', '==', true),
Filter.where('population', '>=', 1000000)
)
)
.get();
// [END firestore_query_or_compound]

console.log('Big cities get: ', bigCities);
console.log('Big cities in California get: ', bigCitiesInCalifornia);
}

async function orderAndLimit(db) {
const citiesRef = db.collection('cities');
// [START firestore_query_order_limit]
Expand Down Expand Up @@ -1071,6 +1106,10 @@ describe('Firestore Smoketests', () => {
return inQueries(db);
});

it('should support or queries', () => {
return orQueries(db);
});

it('should order and limit', () => {
return orderAndLimit(db);
});
Expand Down
2 changes: 1 addition & 1 deletion firestore/main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"license": "ISC",
"dependencies": {
"@google-cloud/firestore": "^6.6.0",
"firebase-admin": "^11.8.0",
"firebase-admin": "^11.9.0",
"firebase-functions": "^4.4.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion firestore/solution-aggregation/functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"compile": "cp ../../../tsconfig.template.json ./tsconfig.json && tsc"
},
"dependencies": {
"firebase-admin": "^11.8.0",
"firebase-admin": "^11.9.0",
"firebase-functions": "^4.4.0"
},
"private": true
Expand Down
2 changes: 1 addition & 1 deletion firestore/solution-deletes/functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"compile": "cp ../../../tsconfig.template.json ./tsconfig.json && tsc"
},
"dependencies": {
"firebase-admin": "^11.8.0",
"firebase-admin": "^11.9.0",
"firebase-functions": "^4.4.0",
"firebase-tools": "^12.2.1"
}
Expand Down
2 changes: 1 addition & 1 deletion firestore/solution-sharded-timestamp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
},
"dependencies": {
"@google-cloud/firestore": "^6.6.0",
"firebase-admin": "^11.8.0"
"firebase-admin": "^11.9.0"
}
}
2 changes: 1 addition & 1 deletion functions/firestore-export/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"compile": "cp ../../tsconfig.template.json ./tsconfig.json && tsc"
},
"dependencies": {
"firebase-admin": "^11.8.0",
"firebase-admin": "^11.9.0",
"firebase-functions": "^4.4.0"
}
}
2 changes: 1 addition & 1 deletion functions/stackdriver-logging/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"dependencies": {
"@google-cloud/logging": "^10.4.1",
"firebase-admin": "^11.8.0",
"firebase-admin": "^11.9.0",
"firebase-functions": "^4.4.0"
}
}
2 changes: 1 addition & 1 deletion management/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"firebase-admin": "^11.8.0",
"firebase-admin": "^11.9.0",
"request-promise": "^4.2.6"
}
}
2 changes: 1 addition & 1 deletion messaging/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"compile": "cp ../tsconfig.template.json ./tsconfig.json && tsc"
},
"dependencies": {
"firebase-admin": "^11.8.0"
"firebase-admin": "^11.9.0"
}
}
Loading