Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(populate): allow populating paths underneath subdocument maps
Fix #9359
- Loading branch information
Showing
3 changed files
with
38 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict'; | ||
|
||
module.exports = function lookupLocalFields(cur, path, val) { | ||
if (cur == null) { | ||
return cur; | ||
} | ||
|
||
if (cur._doc != null) { | ||
cur = cur._doc; | ||
} | ||
|
||
if (arguments.length >= 3) { | ||
cur[path] = val; | ||
return val; | ||
} | ||
|
||
|
||
// Support populating paths under maps using `map.$*.subpath` | ||
if (path === '$*') { | ||
return cur instanceof Map ? | ||
Array.from(cur.values()) : | ||
Object.keys(cur).map(key => cur[key]); | ||
} | ||
|
||
return cur[path]; | ||
}; |