简体   繁体   中英

Firestore iOS DocumentSnapshot `createTime`

I have noticed that firestore iOS SDK (and possibly many other platforms too) don't have access to the createTime property of a document.

With node.js I can access the createTime property of the DocumentSnapshot (which is not mentioned in their official document for node.js either).

My question is, why firebase don't let us use this property (or silently let us use it) even if it is pretty useful for many cases and it is there already?

Also is there any way I could use this property for iOS? Right now I have to manually keep extra field associated with each document (which sounds dumb knowing that there is already a property that firestore keeps).

from the code comment:

/**
 * The time the document was created. Not set for documents that don't
 * exist.
 */
readonly createTime?: Timestamp;

As with most details that are not exposed through public APIs, you should think of that hidden value as an implementation detail that could change in the future. If you depend on it or try to use it in any way, your app could break in the future. As for why it's hidden, only the designers of the system could know that for sure. But you can be sure that, if it's not exposed in the API, they did not intend for you to use it at all.

What you can do instead is simply create your own timestamp field and give it the value you want at the time the document is created. This is very common.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM