创建 Firestore 子集合引用

创建 Firestore 子集合引用

深入探索

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

代码示例

Go

messageRef := client.Collection("rooms").Doc("roomA").
	Collection("messages").Doc("message1")

Java

// Reference to a document in subcollection "messages"
DocumentReference document =
    db.collection("rooms").document("roomA").collection("messages").document("message1");

Node.js

const messageRef = db.collection('rooms').doc('roomA')
  .collection('messages').doc('message1');

PHP

$document = $db
    ->collection('rooms')
    ->document('roomA')
    ->collection('messages')
    ->document('message1');

Python

room_a_ref = db.collection(u'rooms').document(u'roomA')
message_ref = room_a_ref.collection(u'messages').document(u'message1')

Ruby

message_ref = firestore.col("rooms").doc("roomA").col("messages").doc("message1")

后续步骤

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