@@ -56,21 +56,24 @@ module.exports = {
5656 try {
5757 client = setUpDocumentClient ( connectionInfo ) ;
5858 logger . log ( 'info' , connectionInfo , 'Reverse-Engineering connection settings' , connectionInfo . hiddenKeys ) ;
59-
6059 logger . log ( 'info' , { Database : connectionInfo . database } , 'Getting collections list for current database' , connectionInfo . hiddenKeys ) ;
6160 const collections = await listCollections ( connectionInfo . database ) ;
6261
6362 logger . log ( 'info' , { CollectionList : collections } , 'Collection list for current database' , connectionInfo . hiddenKeys ) ;
64- const result = await Promise . all ( collections . map ( async collection => {
63+ const result = await collections . reduce ( async ( acc , collection ) => {
64+ const res = await acc ;
6565 await gremlinHelper . connect ( { ...connectionInfo , collection : collection . id } ) ;
6666 const collectionLebels = await gremlinHelper . getLabels ( ) ;
6767 gremlinHelper . close ( ) ;
6868
69- return {
70- dbName : collection . id ,
71- dbCollections : collectionLebels ,
72- } ;
73- } ) ) ;
69+ return [
70+ ...res ,
71+ {
72+ dbName : collection . id ,
73+ dbCollections : collectionLebels ,
74+ }
75+ ] ;
76+ } , [ ] ) ;
7477
7578 cb ( null , result ) ;
7679 } catch ( err ) {
@@ -90,10 +93,6 @@ module.exports = {
9093 const includeEmptyCollection = data . includeEmptyCollection ;
9194 const includeSystemCollection = data . includeSystemCollection ;
9295 const recordSamplingSettings = data . recordSamplingSettings ;
93- let packages = {
94- labels : [ ] ,
95- relationships : [ ]
96- } ;
9796 const { resource : accountInfo } = await client . getDatabaseAccount ( ) ;
9897 const additionalAccountInfo = await getAdditionalAccountInfo ( data , logger ) ;
9998 const modelInfo = {
@@ -105,7 +104,8 @@ module.exports = {
105104 ...additionalAccountInfo ,
106105 } ;
107106
108- const dbCollectionsPromise = collectionNames . map ( async collectionName => {
107+ const packages = await collectionNames . reduce ( async ( acc , collectionName ) => {
108+ const packages = await acc ;
109109 const labels = collections [ collectionName ] ;
110110
111111 const containerInstance = client . database ( data . database ) . container ( collectionName ) ;
@@ -148,10 +148,13 @@ module.exports = {
148148 const relationshipData = await getRelationshipData ( relationships , collectionName , recordSamplingSettings , fieldInference ) ;
149149 packages . relationships . push ( relationshipData ) ;
150150 gremlinHelper . close ( ) ;
151+
152+ return packages ;
153+ } , {
154+ labels : [ ] ,
155+ relationships : [ ]
151156 } ) ;
152157
153- await Promise . all ( dbCollectionsPromise ) ;
154-
155158 cb ( null , packages . labels , modelInfo , [ ] . concat . apply ( [ ] , packages . relationships ) ) ;
156159 } catch ( err ) {
157160 gremlinHelper . close ( ) ;
0 commit comments