@@ -856,6 +856,10 @@ void ReadDataQueryOperators(firebase::firestore::Firestore* db) {
856
856
FieldValue::String (" San Francisco" ));
857
857
// [END example_filters]
858
858
859
+ // [START query_filter_not_eq]
860
+ cities_ref.WhereNotEqualTo (" capital" , FieldValue::Boolean (false ));
861
+ // [END query_filter_not_eq]
862
+
859
863
}
860
864
861
865
// https://firebase.google.com/docs/firestore/query-data/queries#array_membership
@@ -918,6 +922,82 @@ void ReadDataArrayContainsAnyOperators(firebase::firestore::Firestore* db) {
918
922
// [END cpp_in_filter_with_array]
919
923
}
920
924
925
+
926
+
927
+ void QueryCollectionGroupFilterEq (firebase::firestore::Firestore* db) // 2 TODO
928
+ {
929
+
930
+ using firebase::firestore::CollectionReference;
931
+ using firebase::firestore::FieldValue;
932
+ using firebase::firestore::Error;
933
+ using firebase::firestore::QuerySnapshot;
934
+ using firebase::firestore::DocumentSnapshot;
935
+ using firebase::firestore::Query;
936
+
937
+ // [START query_collection_group_filter_eq]
938
+ db->CollectionGroup (" landmarks" )
939
+ .WhereEqualTo (" type" , FieldValue::String (" museum" )).Get ()
940
+ .OnCompletion ([](const firebase::Future<QuerySnapshot>& future) {
941
+ if (future.error () == Error::kErrorOk ) {
942
+ for (const DocumentSnapshot& document : future.result ()->documents ()) {
943
+ std::cout << document << std::endl;
944
+ }
945
+ } else {
946
+ std::cout << " Error getting documents: " << future.error_message ()
947
+ << std::endl;
948
+ }
949
+ });
950
+ // [END query_collection_group_filter_eq]
951
+
952
+ }
953
+
954
+
955
+ void QueryCollectionGroupDataset (firebase::firestore::Firestore* db)
956
+ {
957
+ using firebase::Future;
958
+ using firebase::firestore::DocumentReference;
959
+ using firebase::firestore::DocumentSnapshot;
960
+ using firebase::firestore::Error;
961
+ using firebase::firestore::FieldValue;
962
+ using firebase::firestore::QuerySnapshot;
963
+ using firebase::firestore::WriteBatch;
964
+
965
+ // [START query_collection_group_dataset]
966
+ // Get a new write batch
967
+ WriteBatch batch = db->batch ();
968
+
969
+ DocumentReference sf_ref = db->Collection (" cities" ).Document (" SF" );
970
+ batch.Set (sf_ref,{{" name" , FieldValue::String (" Golden Gate Bridge" )}, {" type" , FieldValue::String (" bridge" )}});
971
+ batch.Set (sf_ref,{{" name" , FieldValue::String (" Legion of Honor" )}, {" type" , FieldValue::String (" museum" )}});
972
+
973
+ DocumentReference la_ref = db->Collection (" cities" ).Document (" LA" );
974
+ batch.Set (la_ref,{{" name" , FieldValue::String (" Griffith Park" )}, {" type" , FieldValue::String (" park" )}});
975
+ batch.Set (la_ref,{{" name" , FieldValue::String (" The Getty" )}, {" type" , FieldValue::String (" museum" )}});
976
+
977
+ DocumentReference dc_ref = db->Collection (" cities" ).Document (" DC" );
978
+ batch.Set (dc_ref,{{" name" , FieldValue::String (" Lincoln Memorial" )}, {" type" , FieldValue::String (" memorial" )}});
979
+ batch.Set (dc_ref,{{" name" , FieldValue::String (" National Air and Space Museum" )}, {" type" , FieldValue::String (" museum" )}});
980
+
981
+ DocumentReference tok_ref = db->Collection (" cities" ).Document (" TOK" );
982
+ batch.Set (tok_ref,{{" name" , FieldValue::String (" Ueno Park" )}, {" type" , FieldValue::String (" park" )}});
983
+ batch.Set (tok_ref,{{" name" , FieldValue::String (" National Museum of Nature and Science" )}, {" type" , FieldValue::String (" museum" )}});
984
+
985
+ DocumentReference bj_ref = db->Collection (" cities" ).Document (" BJ" );
986
+ batch.Set (bj_ref,{{" name" , FieldValue::String (" Jingshan Park" )}, {" type" , FieldValue::String (" park" )}});
987
+ batch.Set (bj_ref,{{" name" , FieldValue::String (" Beijing Ancient Observatory" )}, {" type" , FieldValue::String (" museum" )}});
988
+
989
+ // Commit the batch
990
+ batch.Commit ().OnCompletion ([](const Future<void >& future) {
991
+ if (future.error () == Error::kErrorOk ) {
992
+ std::cout << " Write batch success!" << std::endl;
993
+ } else {
994
+ std::cout << " Write batch failure: " << future.error_message () << std::endl;
995
+ }
996
+ });
997
+ // [END query_collection_group_dataset]
998
+ }
999
+
1000
+
921
1001
// https://firebase.google.com/docs/firestore/query-data/queries#compound_queries
922
1002
void ReadDataCompoundQueries (firebase::firestore::Firestore* db) {
923
1003
using firebase::firestore::CollectionReference;
@@ -1205,6 +1285,8 @@ void RunAllSnippets(firebase::firestore::Firestore* db) {
1205
1285
snippets::ReadDataExecuteQuery (db);
1206
1286
snippets::ReadDataQueryOperators (db);
1207
1287
snippets::ReadDataCompoundQueries (db);
1288
+ snippets::QueryCollectionGroupDataset (db);
1289
+ snippets::QueryCollectionGroupFilterEq (db);
1208
1290
1209
1291
snippets::ReadDataOrderAndLimitData (db);
1210
1292
0 commit comments