MongoExpiredSessionError: Cannot use a session that has ended'

I’ve been trying to solve this error for 2 days now with no success . In the code below the error happens only when I use ‘cursor.toArray()’ . I don’t know why this happens and I couldn’t find any suggestion by googling the error message :

async function getCollectionsNamesFromAtlas(){
    try {
        await client.connect() ;
      // get collection names in array of strings : ['collection1' , 'collection2']
        let arrayOfCollectionsInfoObjects = await client.db('test').listCollections().toArray();
        arrayOfCollectionsNamesAndDocsInThem ({name})=> name)
        .map(async (collectionName)=> {
            console.log(`collectionName maped is : ${collectionName}`);//string

          let cursorOfDocsInEachCollection =   client.db('test').collection(collectionName).find({}, {projection:{ _id: 0 }});
          let docsInEachCollection = await cursorOfDocsInEachCollection.toArray();//error
           return {collectionName ,docsInEachCollection}
         console.log( arrayOfCollectionsNamesAndDocsInThem);
    finally { await client.close()}