Skip to content

Instantly share code, notes, and snippets.

View ryanmats's full-sized avatar

Ryan Matsumoto ryanmats

View GitHub Profile
@ryanmats
ryanmats / Program.cs
Created May 1, 2018 23:59
AddData1 - New
private static async Task AddData1(string project, string usersCollectionId)
{
FirestoreDb db = FirestoreDb.Create(project);
// [START fs_add_data_1]
DocumentReference docRef = db.Collection(usersCollectionId).Document("alovelace");
Dictionary<string, object> user = new Dictionary<string, object>
{
{ "First", "Ada" },
{ "Last", "Lovelace" },
{ "Born", 1815 }
@ryanmats
ryanmats / Program.cs
Last active May 1, 2018 23:48
AddData1 - Original
private static async Task AddData1(string project)
{
FirestoreDb db = FirestoreDb.Create(project);
// [START fs_add_data_1]
DocumentReference docRef = db.Collection("users").Document("alovelace");
Dictionary<string, object> user = new Dictionary<string, object>
{
{ "First", "Ada" },
{ "Last", "Lovelace" },
{ "Born", 1815 }
require "google/cloud/firestore"
firestore = Google::Cloud::Firestore.new
city_ref = firestore.doc "cities/DC"
city_ref.delete
@ryanmats
ryanmats / gist:c2084909aca7bc0a84119438de18a438
Created April 17, 2018 06:20
Firestore Delete Collection Error Message
ryanmats-macbookpro:firestore ryanmats$ bundle exec ruby delete_data.rb delete_collection
Deleting document LA.
/Library/Ruby/Gems/2.3.0/gems/google-cloud-firestore-0.21.0/lib/google/cloud/firestore/document_reference.rb:420:in `delete': undefined method `batch' for #<Google::Cloud::Firestore::CollectionReference:0x007fd232adba90> (NoMethodError)
from delete_data.rb:70:in `block in delete_collection'
from /Library/Ruby/Gems/2.3.0/gems/google-cloud-firestore-0.21.0/lib/google/cloud/firestore/query.rb:556:in `block in get'
from /Library/Ruby/Gems/2.3.0/gems/grpc-1.11.0-universal-darwin/src/ruby/lib/grpc/generic/active_call.rb:331:in `block in each_remote_read_then_finish'
from /Library/Ruby/Gems/2.3.0/gems/grpc-1.11.0-universal-darwin/src/ruby/lib/grpc/generic/active_call.rb:325:in `loop'
from /Library/Ruby/Gems/2.3.0/gems/grpc-1.11.0-universal-darwin/src/ruby/lib/grpc/generic/active_call.rb:325:in `each_remote_read_then_finish'
from /Library/Ruby/Gems/2.3.0/gems/google-cloud-firestore-0.21.0/lib/google/c
require "google/cloud/firestore"
firestore = Google::Cloud::Firestore.new(project_id: project_id)
cities_ref = firestore.col "cities"
query = cities_ref
query.get do |document_snapshot|
puts "Deleting document #{document_snapshot.document_id}."
document_ref = document_snapshot.ref
document_ref.delete
require "google/cloud/firestore"
firestore = Google::Cloud::Firestore.new
frank_ref = firestore.doc "users/frank"
frank_ref.set({
name: "Frank",
favorites: {
food: "Pizza",
color: "Blue",
subject: "Recess"
},
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<StartupObject>GoogleCloudSamples.QuickStartFirestoreProgram</StartupObject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.1.1-beta" />
<PackageReference Include="Google.Cloud.Firestore" Version="1.0.0-beta02" />
</ItemGroup>
using CommandLine;
using Google.Cloud.Firestore;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace GoogleCloudSamples
{
public class QuickStartFirestoreProgram
@ryanmats
ryanmats / gist:7efc444b9214dbab149d54f7fd446381
Created March 19, 2018 09:35
C# Firestore - UpdateAsync with Nested Fields Dot Notation - Error Message
Unhandled Exception: System.AggregateException: One or more errors occurred. (Status(StatusCode=InvalidArgument, Detail="Entity has a nested entity property named 'Favorites' as well as a property prefixed with 'Favorites.', this results in name collision.")) ---> Grpc.Core.RpcException: Status(StatusCode=InvalidArgument, Detail="Entity has a nested entity property named 'Favorites' as well as a property prefixed with 'Favorites.', this results in name collision.")
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Google.Api.Gax.Grpc.ApiCallRetryExtensions.<>c__DisplayClass0_0`2.<<WithRetry>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Google.Cloud.Firestore.WriteB
@ryanmats
ryanmats / gist:04a49f75b8806550175a8d8542d2d0fb
Created March 16, 2018 20:40
Calling GetSnapshotAsync on Collection Reference - Error Message
Program.cs(77,53): error CS1061: 'CollectionReference' does not contain a definition for 'GetSnapshotAsync' and no extension method 'GetSnapshotAsync' accepting a first argument of type 'CollectionReference' could be found (are you missing a using directive or an assembly reference?) [/Users/ryanmats/testing/dotnet-docs-samples/firestore/api/QuickStartFirestore/QuickStartFirestore.csproj]
The build failed. Please fix the build errors and run again.