Node.js 如何在控制台中打印完整的查询输出

Node.js 如何在控制台中打印完整的查询输出,node.js,mongodb,aggregate,pipeline,Node.js,Mongodb,Aggregate,Pipeline,我正在nodejs中编写mongodb聚合查询。我尽了最大的努力想弄明白,但代码在我的方法中不起作用。如何在控制台中打印完整的查询输出 const { MongoClient, ObjectId } = require('mongodb'); async function main(){ const uri = `mongodb://${dbUser}:${dbPassword}@${ipAddress}:${port}/${dbName}`;

我正在nodejs中编写mongodb聚合查询。我尽了最大的努力想弄明白,但代码在我的方法中不起作用。如何在控制台中打印完整的查询输出

    const { MongoClient, ObjectId } = require('mongodb');
    
    async function main(){
    
        const uri = `mongodb://${dbUser}:${dbPassword}@${ipAddress}:${port}/${dbName}`;
    
        const client = new MongoClient(uri);
    
        try {
    
            await client.connect();
    
            await printStudents(client,"541516516165164489d3aee");
    
        } finally {
            await client.close();
        }
    }
    
    main().catch(console.error);
    
    /**
     * Print the students for a given schoolId
     * @param {MongoClient} client A MongoClient that is connected to a cluster with the education database
     * @param {ObjectId} schoolId
     */
    
    async function printStudents(client,schoolId){
        const pipeline = [
            { 
                '$match' : { '_id' : ObjectId(schoolId) } 
            },
            {
              '$project': 
              {
                '_id':  { '$toString': '$_id'}
              }
            },
            {
                '$lookup':
                {
                    'from': 'students',
                    'localField': '_id',
                    'foreignField': 'schools',
                    'as': 'Students'
                }
            }
        ]; 
    
        const docs = client.db("education").collection("schools").aggregate(pipeline).toArray();
    console.log(docs);

    }

我希望我能得到一些关于如何正确处理这个问题的好建议

打印前,请尝试等待聚合结果。请向我们显示您的输出。