.back()
The.back() method traverses up the chain to parent references. It’s useful for navigating back after descending into nested properties or returning to the root database.
Signature
Parameters
Number of levels to go back. Special values:
1(default): Go back one level-1: Go to rootInfinity: Go to root2,3, etc.: Go back multiple levels
Property path to traverse. Can be:
- String with dots:
'opt.peers' - Array of keys:
['opt', 'peers']
Function called for each parent until it returns a value.Signature:
function(parent, opt)parent- Parent chain contextopt- Options passed through
Return Value
Returns a GUN chain reference to the parent (or root) for method chaining.Examples
Go Back One Level
Return to Root
Multiple Levels
Access Metadata Path
Traverse with Callback
Build Path String
Navigation Pattern
Implementation Details
From the source code (back.js:4-39):.back() method:
- With no args or
1: goes back one level - With
-1orInfinity: returns root - With string/array: accesses chain metadata
- With callback: traverses until callback returns a value
- With number > 1: recursively goes back N levels
Chain Hierarchy
Root Access Pattern
Metadata Access
Notes
.back()with no args goes back one level.back(-1)and.back(Infinity)return the root- Useful for complex navigation patterns
- Returns immediately (synchronous)
- The callback version traverses until it gets a return value
- Path access is useful for getting configuration from the root
- Each chain maintains a reference to its parent via
._back - Cannot go “forward” - only up the chain