These are chat archives for Automattic/mongoose

Nov 2017
Fabian Kögel
Nov 24 2017 14:30
Two quick questions:
  1. Is it intended that population in nested arrays is not possible with explicit paths? Example: doc.populate('array.0.1.field') for document {array:[[{field:'00'},{field:'01'}]] }
  2. Is there any hook that is executed on embedded schemas? I get a document from my DB which might have multiple nested levels of the same self-referencing Schema var nestedSchema = new Schema({'sub_docs': [nestedSchema], 'reference': {'type': ObjectId, 'ref':'SomeModel'}}) and I want to populate every level when it is instanced. Since I do not know the number of levels before the query, I cannot use the auto-populate plugin or any list of paths for populate... So I would like to use some kind of post-init hook on embedded schemas
Regarding 1.: If I do not nest arrays directly, but use an object in between the path resolution works. E.g. doc.populate('array.0.container.1.field') for document {array: [ {container: [ {field:'00'}, {field:'01'} ] } ]}