This decodes a MongoDB-safe path string into a regular path string.
Path
Paths are returned by collection.parsePath(path). They are used to make writing generic metadata-based code easier.
Path is also able to deal with denormalized paths as well.
See paths for more information.
static
This encodes a regular path into a MongoDB-safe path string.
MongoDB does not support periods appearing inside key names inside objects stored in MongoDB. However, sometimes we need to store Tyranid metadata inside the database that uses Tyranid paths. This method encodes those values into something that MongoDB will store.
This returns the name for the populated field the given path.
name | populateNameFor(denormal: false)/u> | populateNameFor(denormal: true) |
---|---|---|
'customer' | 'customer$' | 'customer_' |
'customerId' | 'customer' | 'customer_' |
This resolves a new Path instance from a parent path and a child path.
If both the parent path and child path are missing, this will return undefined.
instance
This returns 'path'.
This returns the object that this name path is relative to (usually a collection, but it could be relative to another name path).
This is a more detailed version of tail.
Often you are only interested in the end of the path which has the Type of the path you are working with.
This is a shortcut for skipArrays(this.pathFields[this.pathFields.length-1]).
If the path parent.children refers to a an array of string, the tail points at the array but detail points at the contents of the array -- i.e. the string field.
This array contains the Field for each step along the path. This is a parallel array to path.
This walks the obj according to this path and returns the values at this path. (There can be multiple values if the path crosses any arrays. If so, this method will return duplicate values if values occur more than once. See Path.uniq().)
This returns the number of path groups inside this path. Groups are created by using a '|' instead of a '.' as a separatror.
This returns the label for the given group. Groups are created by using a '|' instead of a '.' as a separatror.
This returns the range of fields for the given group. Groups are created by using a '|' instead of a '.' as a separatror.
This returns a simple identifier for this field that does not have periods (.) in it.
This can be useful for some libraries which don't deal with with embedded periods like getFieldDecorator.
For example:
Path | Identifier |
---|---|
siblings._.name | siblings___name |
name.first | name_first |
age | age |
This returns true if this path represents a historical property.
This contains the full path label for this name path. This includes both the group and path portions.
For example, given a path of orders.location|city.name:
Method | Label |
---|---|
groupLabel(0) | Order Locations |
pathLabel | City |
label | Order Location City |
This contains the full, unparsed path that was passed into the constructor.
This returns a new Path relative to the current name path. Any objects passed into methods on this new Path like get, set, and so on must also be relative in the same way.
This contains the path split up into individual strings for steps on the path.
name | path(name) |
---|---|
'name' | [ 'name' ] |
'name.first' | [ 'name', 'first' ] |
'organization_.owner_.name.first' | [ 'organization_', 'owner_', 'name', 'first' ] |
This contains the full path label for this name path except for the group portion of this path (if any).
This returns a verbose description of the path at position idx along the path. This is useful for error messages in parsing.
This adds the current path to the given projection.
If this path refers to a computed field, then all of the fields needed to perform the computation will be added to the projection as well.
This walks the obj according to this path and sets the given value at that point in the path.
opts is as follows:
Option | Type | Notes |
---|---|---|
{ | ||
create: | boolean | If true, set() will create any missing ancestor objects or arrays as needed.. |
ignore: | boolean | If true, set() will silently fail if ancestor objects or arrays are missing.. |
} |
This contains the simplified path of this field.
Simplified paths remove the array contents reference and are useful when working with MongoDB projections. For example:
Path | Simplified Path |
---|---|
siblings._.name | siblings.name |
siblings.0.name | siblings.name |
name.first | name.first |
age | age |
See Paths for more information.
This contains the simplified path of this field that includes array indices.
Simplified paths remove the array contents reference and are useful when working with MongoDB projections. For example:
Path | Simplified Path |
---|---|
siblings._.name | siblings.name |
siblings.0.name | siblings.0.name |
name.first | name.first |
age | age |
See Paths for more information.
This is a shortcut for this.pathFields[this.pathFields.length-1]. Often you are only interested in the end of the path which has the Type of the path you are working with.
This property is related to detail. If the path parent.children refers to a an array of string, the tail points at the array but detail points at the contents of the array -- i.e. the string field.
This walks the obj according to this path and returns the uniq values at this path it finds. (There can be multiple values if the path crosses any arrays.)
This resolves a new Path instance that is relative to the current Path.