添加 Firestore 文档

使用集合让一切井井有条 根据您的偏好保存内容并对其进行分类。

添加 Firestore 文档

深入探索

如需查看包含此代码示例的详细文档,请参阅以下内容:

代码示例

C#

await db.Collection("cities").Document("new-city-id").SetAsync(city);

Go

_, err := client.Collection("cities").Doc("new-city-id").Set(ctx, data)
if err != nil {
	// Handle any errors in an appropriate way, such as returning them.
	log.Printf("An error has occurred: %s", err)
}

Java

db.collection("cities").document("new-city-id").set(data);

Node.js

await db.collection('cities').doc('new-city-id').set(data);

PHP

$db->collection('samples/php/cities')->document('new-city-id')->set($data);

Python

db.collection(u'cities').document(u'new-city-id').set(data)

Ruby

city_ref = firestore.doc "#{collection_path}/new-city-id"
city_ref.set data

后续步骤

如需搜索和过滤其他 Google Cloud 产品的代码示例,请参阅 Google Cloud 示例浏览器