f-miyu / Plugin.CloudFirestore

MIT License
123 stars 44 forks source link

Create empty documents #68

Open nnovalbos opened 3 years ago

nnovalbos commented 3 years ago

Hello, I would like to create empty documents, that is, that only have the reference.

In android, the following code works perfectly for me:

var documentReference = CrossCloudFirestore.Current
                             .Instance
                             .Collection(collectionPath)
                             .Document(documentPath);

await documentReference.SetAsync(new Dictionary<string, object>());

But in iOS I get the following error:

System.ArgumentException: count
at Foundation.NSDictionary`2[TKey,TValue].FromObjectsAndKeys (System.Object[] objects, System.Object[] keys, System.nint count) [0x0005d] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.6.0.15/src/Xamarin.iOS/Foundation/NSDictionary_2.cs:222 
  at Firebase.CloudFirestore.DocumentReference.SetData (System.Collections.Generic.Dictionary`2[TKey,TValue] documentData, Firebase.CloudFirestore.DocumentActionCompletionHandler completion) [0x0002a] in <853d9368ce8546f280c95473c4829237>:0 
  at Plugin.CloudFirestore.DocumentReferenceWrapper.SetAsync[T] (T documentData) [0x0001d] in <65f715c16e684ecea31762bc9b39b9f7>:0 
  at ....Repository.FirestoreRepository.PostOneReferenceAsync (System.String path) [0x0009a] in /......../Repository/FirestoreRepository.cs:288 }
    base: {System.SystemException}
    Message: "count"
    ParamName: (null)
    Non-public members:

To solve it I have to add a value, which I don't need. Would there be any option to do this on iOS?

Thanks

angelru commented 3 years ago

and if you try with merge: true?

https://stackoverflow.com/questions/65604626/are-empty-documents-in-firestore-deleted/65604748