Firestore ドキュメントのタイムスタンプを更新する

コレクションでコンテンツを整理 必要に応じて、コンテンツの保存と分類を行います。

Firestore ドキュメントのタイムスタンプを更新する

もっと見る

このコードサンプルを含む詳細なドキュメントについては、以下をご覧ください。

コードサンプル

C#

DocumentReference cityRef = db.Collection("cities").Document("new-city-id");
await cityRef.UpdateAsync("Timestamp", Timestamp.GetCurrentTimestamp());

Go

_, err := client.Collection("objects").Doc("some-id").Set(ctx, map[string]interface{}{
	"timestamp": firestore.ServerTimestamp,
}, firestore.MergeAll)
if err != nil {
	// Handle any errors in an appropriate way, such as returning them.
	log.Printf("An error has occurred: %s", err)
}

Java

DocumentReference docRef = db.collection("objects").document("some-id");
// Update the timestamp field with the value from the server
ApiFuture<WriteResult> writeResult = docRef.update("timestamp", FieldValue.serverTimestamp());
System.out.println("Update time : " + writeResult.get());

Node.js

// Create a document reference
const docRef = db.collection('objects').doc('some-id');

// Update the timestamp field with the value from the server
const res = await docRef.update({
  timestamp: FieldValue.serverTimestamp()
});

PHP

$docRef = $db->collection('samples/php/objects')->document('some-id');
$docRef->update([
    ['path' => 'timestamp', 'value' => FieldValue::serverTimestamp()]
]);

Python

city_ref = db.collection(u'objects').document(u'some-id')
city_ref.update({
    u'timestamp': firestore.SERVER_TIMESTAMP
})

Ruby

city_ref = firestore.doc "#{collection_path}/new-city-id"
city_ref.update({ timestamp: firestore.field_server_time })

次のステップ

他の Google Cloud プロダクトに関連するコードサンプルの検索およびフィルタ検索を行うには、Google Cloud のサンプルをご覧ください。