خرید بک لینک

Vote count: 0

This function retus all collections in a MongoDB database, with the number of documents in each collection (bluebird promises).

function listMongoCollections(db) {
    var promises = []
    db.listCollections().toArray().then((docs) => {

        docs.forEach((doc) => {

            promises.push(
                new Promise((resolve) => {
                    db.collection(doc.name).count().then((count) => {
                        doc.count = count
                        resolve()
                    })
                })
            )
        })

        Promise.all(promises).then(() => {
            retu docs
        })
    })
}

Is there a simpler way to do this? Using this method will flood an app with code, and I haven't even included error handling.

asked 39 secs ago

برچسب: نویسنده: استخدام کار تاريخ: دوشنبه 17 خرداد 1395 ساعت: 17:51

صفحه بندی