Skip to content

Commit b2f129e

Browse files
authored
Collection group and cache size snippets (firebase#14)
1 parent f2981e4 commit b2f129e

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

firestore/test.firestore.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ describe("firestore", () => {
3939
// [END initialize_persistence]
4040
});
4141

42+
it("should be able to set the cache size", () => {
43+
// [START fs_setup_cache]
44+
firebase.firestore().settings({
45+
cacheSizeBytes: firebase.firestore.CACHE_SIZE_UNLIMITED
46+
});
47+
// [END fs_setup_cache]
48+
});
49+
4250
it("should be able to enable/disable network", () => {
4351
var disable =
4452
// [START disable_network]
@@ -928,6 +936,69 @@ describe("firestore", () => {
928936
// [END paginate]
929937
});
930938
});
939+
940+
describe('collectionGroup(landmarks', () => {
941+
it("should setup example data", () => {
942+
// [START fs_collection_group_query_data_setup]
943+
var citiesRef = db.collection('cities');
944+
945+
var landmarks = Promise.all([
946+
citiesRef.doc('SF').collection('landmarks').doc().set({
947+
name: 'Golden Gate Bridge',
948+
type: 'bridge'
949+
}),
950+
citiesRef.doc('SF').collection('landmarks').doc().set({
951+
name: 'Legion of Honor',
952+
type: 'museum'
953+
}),
954+
citiesRef.doc('LA').collection('landmarks').doc().set({
955+
name: 'Griffith Park',
956+
type: 'park'
957+
}),
958+
citiesRef.doc('LA').collection('landmarks').doc().set({
959+
name: 'The Getty',
960+
type: 'museum'
961+
}),
962+
citiesRef.doc('DC').collection('landmarks').doc().set({
963+
name: 'Lincoln Memorial',
964+
type: 'memorial'
965+
}),
966+
citiesRef.doc('DC').collection('landmarks').doc().set({
967+
name: 'National Air and Space Museum',
968+
type: 'museum'
969+
}),
970+
citiesRef.doc('TOK').collection('landmarks').doc().set({
971+
name: 'Ueno Park',
972+
type: 'park'
973+
}),
974+
citiesRef.doc('TOK').collection('landmarks').doc().set({
975+
name: 'National Museum of Nature and Science',
976+
type: 'museum'
977+
}),
978+
citiesRef.doc('BJ').collection('landmarks').doc().set({
979+
name: 'Jingshan Park',
980+
type: 'park'
981+
}),
982+
citiesRef.doc('BJ').collection('landmarks').doc().set({
983+
name: 'Beijing Ancient Observatory',
984+
type: 'museum'
985+
})
986+
]);
987+
// [END fs_collection_group_query_data_setup]
988+
return landmarks;
989+
});
990+
991+
it("should query a collection group", () => {
992+
// [START fs_collection_group_query]
993+
var museums = db.collectionGroup('landmarks').where('type', '==', 'museum');
994+
museums.get().then(function (querySnapshot) {
995+
querySnapshot.forEach(function (doc) {
996+
console.log(doc.id, ' => ', doc.data());
997+
});
998+
});
999+
// [END fs_collection_group_query]
1000+
});
1001+
});
9311002
});
9321003

9331004
// TODO: Break out into separate file

0 commit comments

Comments
 (0)