Stay organized with collections
Save and categorize content based on your preferences.
Properties
Optional source
source: "default" | "server" | "cache"
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2022-07-27 UTC.
[null,null,["Last updated 2022-07-27 UTC."],[],[],null,["# GetOptions | JavaScript SDK\n\n- [firebase](/docs/reference/js/v8/firebase).\n- [firestore](/docs/reference/js/v8/firebase.firestore).\n- GetOptions\n===================================================================================================================\n\nAn options object that configures the behavior of `get()` calls on\n`DocumentReference` and `Query`. By providing a `GetOptions` object, these\nmethods can be configured to fetch results only from the server, only from\nthe local cache or attempt to fetch results from the server and fall back to\nthe cache (which is the default).\n\nIndex\n-----\n\n### Properties\n\n- [source](/docs/reference/js/v8/firebase.firestore.GetOptions#source)\n\nProperties\n----------\n\n### Optional source\n\nsource: \"default\" \\| \"server\" \\| \"cache\" \nDescribes whether we should get from server or cache.\n\nSetting to `default` (or not setting at all), causes Firestore to try to\nretrieve an up-to-date (server-retrieved) snapshot, but fall back to\nreturning cached data if the server can't be reached.\n\nSetting to `server` causes Firestore to avoid the cache, generating an\nerror if the server cannot be reached. Note that the cache will still be\nupdated if the server request succeeds. Also note that latency-compensation\nstill takes effect, so any pending write operations will be visible in the\nreturned data (merged into the server-provided data).\n\nSetting to `cache` causes Firestore to immediately return a value from the\ncache, ignoring the server completely (implying that the returned value\nmay be stale with respect to the value on the server.) If there is no data\nin the cache to satisfy the `get()` call, `DocumentReference.get()` will\nreturn an error and `QuerySnapshot.get()` will return an empty\n`QuerySnapshot` with no documents."]]
An options object that configures the behavior of
get()
calls onDocumentReference
andQuery
. By providing aGetOptions
object, these methods can be configured to fetch results only from the server, only from the local cache or attempt to fetch results from the server and fall back to the cache (which is the default).