I have been trying to solve the problem with the following code for 2 days now with no success , the code gives me the error ‘MongoExpiredSessionError: Cannot use a session that has ended’ :
async function getCollectionsNamesFromAtlas(){
try {
await client.connect() ;
let arrayOfCollectionsInfoObjects = await client.db('test').listCollections().toArray();
arrayOfCollectionsNamesAndDocsInThem =arrayOfCollectionsInfoObjects.map( ({name})=> name) /* name of the collection*/
.map(async (collectionName)=> {
console.log(`collectionName maped is : ${collectionName}`); // array
let cursorOfDocsInEachCollection = client.db('test').collection(collectionName).find({}, {projection:{ _id: 0 }});
console.log(cursorOfDocsInEachCollection) // prints the cursor
let docsInEachCollection = await cursorOfDocsInEachCollection.toArray();
console.log(docsInEachCollection)//MongoExpiredSessionError
// return {collectionName ,docsInEachCollection}
// })
// console.log( arrayOfCollectionsNamesAndDocsInThem);
})
}
catch(error){console.log(error)}
finally { await client.close()}
}
why I am getting this error ?