use of com.google.cloud.firestore.CollectionReference in project native-image-support-java by GoogleCloudPlatform.
the class FirestoreSampleApplication method createUserDocumentPojo.
private static void createUserDocumentPojo(Firestore db) throws Exception {
CollectionReference collectionReference = db.collection(USERS_COLLECTION);
WriteResult result = collectionReference.document().set(new Person("Alan", "Turing", 1912)).get();
System.out.println("Created user by POJO. Timestamp: " + result.getUpdateTime());
}
use of com.google.cloud.firestore.CollectionReference in project java-docs-samples by GoogleCloudPlatform.
the class ManageDataSnippetsIT method testWriteBatchIsSuccessful.
@Test
public void testWriteBatchIsSuccessful() throws Exception {
manageDataSnippets.writeBatch();
CollectionReference collection = db.collection("cities");
ApiFuture<DocumentSnapshot> document = collection.document("NYC").get();
assertTrue(document.get().exists());
DocumentReference documentReference = collection.document("SF");
Map<String, Object> data = getDocumentDataAsMap(documentReference);
assertTrue(data.containsKey("population"));
document = collection.document("LA").get();
assertFalse(document.get().exists());
}
use of com.google.cloud.firestore.CollectionReference in project java-docs-samples by GoogleCloudPlatform.
the class QueryDataSnippets method createRangeQuery.
/**
* An instance of a valid range/inequality query : range operators are limited to a single field.
*
* @return query
*/
Query createRangeQuery() {
CollectionReference cities = db.collection("cities");
// [START fs_range_query]
Query validQuery1 = cities.whereGreaterThanOrEqualTo("state", "CA").whereLessThanOrEqualTo("state", "IN");
Query validQuery2 = cities.whereEqualTo("state", "CA").whereGreaterThan("population", 1000000);
// [END fs_range_query]
return validQuery1;
}
use of com.google.cloud.firestore.CollectionReference in project java-docs-samples by GoogleCloudPlatform.
the class QueryDataSnippets method createInvalidRangeQuery.
/**
* An instance of an invalid range query : range operators are limited to a single field.
*
* @return query
*/
Query createInvalidRangeQuery() {
CollectionReference cities = db.collection("cities");
// Violates constraint : range operators are limited to a single field
// [START fs_invalid_range_query]
Query invalidRangeQuery = cities.whereGreaterThanOrEqualTo("state", "CA").whereGreaterThan("population", 100000);
// [END fs_invalid_range_query]
return invalidRangeQuery;
}
use of com.google.cloud.firestore.CollectionReference in project java-docs-samples by GoogleCloudPlatform.
the class QueryDataSnippets method createAQueryAlternate.
/**
* Creates a sample query.
*
* @return query
*/
Query createAQueryAlternate() throws Exception {
// [START fs_create_query_country]
// Create a reference to the cities collection
CollectionReference cities = db.collection("cities");
// Create a query against the collection.
Query query = cities.whereEqualTo("state", "CA");
// retrieve query results asynchronously using query.get()
ApiFuture<QuerySnapshot> querySnapshot = query.get();
for (DocumentSnapshot document : querySnapshot.get().getDocuments()) {
System.out.println(document.getId());
}
// [END fs_create_query_country]
return query;
}
Aggregations