Interface CollNumCoercionCfg

Overview

💡Tip: read the documentation for CollectionSerDesConfig.enableBigNumbers before reading this.

This method of configuring the numerical deserialization behavior uses a configuration object that maps paths to coercion types.

If you'd prefer to use a more flexible approach, you can use the CollNumCoercionFn type to define the coercion for each path.

Example

const orders = db.collection<Order>('orders', {
serdes: {
enableBigNumbers: {
'*': 'number',
'discount': 'bigint',
'items.*.price': 'bignumber',
},
},
});

The configuration object

The configuration object is a map of paths to coercion types.

These paths may also contain wildcards ('*'), which matches any single element in the path at that position.

  • However, it will not match multiple elements (or no elements) in the path.
  • For example, 'foo.*' will match 'foo.bar', but not 'foo' or 'foo.bar.baz'.

Paths containing numbers (e.g. 'arr.0') will match both arr: ['me!'] and arr: { '0': 'me!' }.

🚨Important: There must be a '*' key in the configuration object, which will be used as the default coercion for all paths that do not have a specific coercion defined.

  • This key is required, and the configuration will throw an error if it is not present.

Using a single CollNumCoercion

You may simply use { '*': '<type>' } to return a single coercion type for all paths.

This is specifically optimized to be just as fast as using () => '<type>'.

See

  • CollectionSerDesConfig.enableBigNumbers
  • CollNumCoercionFn
  • CollNumCoercion
interface CollNumCoercionCfg {
    *: CollNumCoercion;
    [path: string]: CollNumCoercion;
}

Indexable

[path: string]: CollNumCoercion

Properties

*

Properties