1

When I try to get the result of Aggregation, I will get an Pool Destroyed error.

A similar question in How to solve MongoError: pool destroyed while connecting to CosmosDB but first I don't set replicaSet and second the fix for microsoft doesn't work for me either.

I am using mongodb 6.4.1, nodejs 11.3.0, windows 10. MongoDb Atlas. (There is no need to set up ReplicaSet)

const collection = database.db("wholeData").collection("someData");
collection.findOne({"date": ts.todayTS}).then((data)=>{
collection.aggregate([
                {$match: {}}
            ]).toArray(function(err, docs){
                console.log(err);
                console.log(docs);
            })
});

Other operations are OK for me, like collection.findOne does have a result here.

I expect the output of all documents in this database, but it returns a pool destroyed error and nothing in result.

  • it seems like you are not closing the mongo connection, try to use mongo.close() after complete aggregation. – Vijay Rajpurohit Sep 03 '19 at 15:25
  • @VijayRajpurohit It is actually inside the MongoClient.connect and there would be a database.close when at the end. Do I really need to add a db.close() here just after the aggregate? The problem is pool destroyed and if I didn't close the mongo connection, why it's destroyed during an aggregate? – Michael Sun Sep 04 '19 at 19:07

0 Answers0