When one response needs data from several maps, _.merge combines their fields into a single flat map. That convenience comes with a catch: fields sharing a name create a merge conflict that must be handled deliberately. section 11.5
Choose between nesting and merging according to the shape and conflict profile you need:
- Nest external data under a field such as extendedInfo when avoiding conflicts matters more than keeping the result flat. section 11.5
- Merge database and API fields when a flat result is useful and overlapping field names are absent or already accounted for. section 11.5
Combining book data
Given database data containing isbn and available, and Open Library data containing title, subtitle, number_of_pages, full_title, publish_date, and publishers, calling _.merge(dataFromDb, dataFromOpenLib) produces one map containing fields from both sources. section 11.5
Table 11.1 Two ways to combine hash maps (view table figure)
Compare nesting and merging by result shape, conflict handling, and practical trade-offs. section 11.5
