I am trying to create a sub-collection in a document and set data to documents in the created sub-collection.
I have tried this but the program crashes every time I run this.
await Firestore.instance
.collection('/path')
.document("documentPath")
.collection('/subCollectionPath')
.document()
.setData({
'TestData': "Data",
}).then((onValue) {
print('Created it in sub collection');
}).catchError((e) {
print('======Error======== ' + e);
});
I have also looked online but I cannot find any documentation for it.
Any ideas?
When I try the above code, the app crashes with the following message
flutter: EVENT StorageTaskEventType.success
*** First throw call stack:
(
0 CoreFoundation 0x0000000111eb61bb __exceptionPreprocess + 331
1 libobjc.A.dylib 0x0000000111454735 objc_exception_throw + 48
2 Runner 0x000000010ce707b1 -[FIRFirestore documentWithPath:] + 257
3 Runner 0x000000010d10662c getDocumentReference + 124
4 Runner 0x000000010d109879 -[FLTCloudFirestorePlugin handleMethodCall:result:] + 2665
5 Flutter 0x000000010e5b99a2 __45-[FlutterMethodChannel setMethodCallHandler:]_block_invoke + 115
6 Flutter 0x000000010e5d6616 _ZNK5shell21PlatformMessageRouter21HandlePlatformMessageEN3fml6RefPtrIN5blink15PlatformMessageEEE + 166
7<…>
Lost connection to device.
Click on + Add Action. On the right side, search and select the Database action and then select Create Document. Set the Collection to the subcollection i.e messages. You can create a subcollection document under an existing reference if there is a subcollection defined.
FlutterFire is a set of Flutter plugins which connect your Flutter application to Firebase.
To delete an entire collection or subcollection in Cloud Firestore, retrieve all the documents within the collection or subcollection and delete them. If you have larger collections, you may want to delete the documents in smaller batches to avoid out-of-memory errors.
final databaseReference = Firestore.instance;
databaseReference.collection('main collection name').document( unique id).collection('string name').document().setData(); // your answer missing **.document()** before setData
this is the right Syntex
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With