Flutter 如何使用帮助文档ID更新Cloud firestore文档字段?
在这里,我试图在documentID(stringkeyid)的帮助下更新用户的退出时间。当用户在给定的INPUTFIELD中添加DOCUMENTID或keyId以及退出时间:Value(get updated)时,更新就完成了。cloud_数据库中的数据以如下方式更新(keyId(KzlWLHJc0di6QziewVV7)=>INPUTFIELD=>Update done in The cloud_数据库) 但是现在我已经为每个用户添加了身份验证。数据库为每个用户单独存储数据。现在我不知道在第二个代码中我还能做什么修改,以使工作过程与上面的代码类似Flutter 如何使用帮助文档ID更新Cloud firestore文档字段?,flutter,dart,google-cloud-firestore,Flutter,Dart,Google Cloud Firestore,在这里,我试图在documentID(stringkeyid)的帮助下更新用户的退出时间。当用户在给定的INPUTFIELD中添加DOCUMENTID或keyId以及退出时间:Value(get updated)时,更新就完成了。cloud_数据库中的数据以如下方式更新(keyId(KzlWLHJc0di6QziewVV7)=>INPUTFIELD=>Update done in The cloud_数据库) 但是现在我已经为每个用户添加了身份验证。数据库为每个用户单独存储数据。现在我不知道在第
2nd code:
String keyId;
CollectionReference vaultCollection = Firestore.instance.collection('student entry').document(uid).collection('vault'); //Where should i add keyId new code
DocumentReference doc=vaultCollection.document();
doc.updateData({
'Exit-time': date,
});
我假设您有
文档ID
,您想在其中更新数据。您可以将setData
函数与merge:true
一起使用。您不必获取数据来更新它
在您的示例中,KeyId
是要更新数据的文档ID
第一个代码
DocumentReference documentReference = Firestore.instance.collection('student entry').document(keyId);
documentReference.setData({'Exit-time': date},merge:true);
第二代码
DocumentReference documentReference = Firestore.instance.collection('student entry').document(keyId);
documentReference.setData({'Exit-time': date},merge:true);
现在,由于您将数据存储在子集合中
。因此只会更新文档引用
DocumentReference documentReference = Firestore.instance.collection('student entry').document(uid).collection('vault').document(keyId);
documentReference.setData({'Exit-time': date},merge:true);
希望这有帮助