Skip to content
On this page

Firestore and Database global Options

If you find yourself passing around the same options to useDocument(), useObject(), ..., you can use the global options to avoid repeating yourself:

import { globalFirestoreOptions } from 'vuefire'

globalFirestoreOptions.converter = ...

Changing these options will affect all calls to useDocument(), useObject(), ... in your application and the Options API usage as well ($firestoreBind(), $rtdbBind()).

In both scenarios, you need to make sure the returned objects contain their original id so other VueFire functionalities can work correctly. The easies way to do this is by reusing the default serialize/converter:

import { globalFirestoreOptions } from 'vuefire'

const defaultConverter = globalFirestoreOptions.converter
globalFirestoreOptions.converter = {
  toFirestore: defaultConverter.toFirestore,
  fromFirestore: (snapshot, options) => {
    const data = defaultConverter.fromFirestore(snapshot, options)
    // add anything custom to the returned object
    data.metadata = snapshot.metadata
    return data

Released under the MIT License.