简体   繁体   English

将更多数据推送到相同的文档 ID

[英]Pushing more data to the same document id

Im pretty new to Flutter, which is why I seek some help here.我对 Flutter 很陌生,这就是我在这里寻求帮助的原因。 I would like to push/add more exercises to the same document id in firestore.我想向 Firestore 中的同一文档 ID 推送/添加更多练习。 So it is stored as one workout.所以它被存储为一个锻炼。 I have made a class called exercise, I would like to ad more under.我做了一个class叫做练习,想多下广告。 I have included a picture of the firestore.我附上了一张火炉的照片。

Firestore 示例

This is the following way I add to firestore:这是我添加到firestore的以下方式:

final exercise = Exercise(
  date: DateTime.now(),
  name: 'Leg',
  reps: ['1', '2'],
  weight: ['50', '40']);

String id = FirebaseFirestore.instance.collection('workouts').doc().id;
FirebaseFirestore.instance
    .collection('workouts')
    .doc(id)
    .set(exercise.toFirestore());

With little information, if you want to add to the array, for example increase the list of reps (From ['1','2'] to this ['1','2','3'], you can do this:几乎没有信息,如果你想添加到数组中,例如增加代表列表(从['1','2']到这个['1','2','3'],你可以做这个:

String id = FirebaseFirestore.instance.collection('workouts').doc().id;
FirebaseFirestore.instance
    .collection('workouts')
    .doc(id)
    .update({'refs': Fielvalue.arrayUnion(['3'])});

But if you want to include fields to an already made document:但是,如果您想将字段包含到已制作的文档中:

var db = FirebaseFirestore.instance;
final batch = db.batch();
var workout = db.collection("workouts").doc("your document");

//update
batch.update(workout, {"situps": ['1','2','3','4']});

// Commit the batch
batch.commit().then((_) {
  // done
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Firebase:将文档 ID 存储在文档本身中,同时作为 Map 推送 - Firebase: Storing a document ID within document itself while pushing as a Map 如何防止恶意用户将数据推送到 Firebase 中的文档中? - How to prevent a malicious user from pushing data into a document in Firebase? 如何创建一个新表,只保留Bigquery中相同ID下超过5条数据记录的行 - How to create a new table that only keeps rows with more than 5 data records under the same id in Bigquery Firestore 通过函数将文档 ID 添加到数据 - Firestore add Document ID to Data via functions 没有 id 的 firestore 文档更新数据 - firestore document update data without id 使用动态 Id 更新 firebase 文档中的数据 - UPDATE the data on a firebase document using dynamic Id Cloud FireStore 多个文档具有相同的 iD,即用户 UID - Cloud FireStore multiple document with same iD which is the user UID 获取更多关于 Gremlin 遍历的数据而不仅仅是节点 ID? - Getting more data on Gremlin traversal than just node id? 数据停止推送到 bigquery - Data stops pushing to bigquery 从 Firebase 具有特定 ID 的文档中提取时,表达式类型不明确,没有更多上下文,映射到 Codable - Error Type of expression is ambiguous without more context when pulling from Firebase Document with specific ID, mapping to Codable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM