async function query1() {
    let db;
    const client = new MongoClient(uri, { useUnifiedTopology: true });
    try {
        await client.connect();
        db = client.db("Arts");
        const artistsCollection = db.collection("artists");

        const aggregation = [
            { $group: { _id: "$nationality.region", count: { $sum: 1 } } },
            { $sort: { count: -1 } },
        ];
        const res = await artistsCollection
            .aggregate(aggregation)
            .limit(1)
            .toArray();
        console.log(
            "Query 1: The region with the most artists from artists collection is: ",
            res
        );
    } catch (err) {
        console.log("error", err);
    } finally {
        await client.close();
    }
}
//At least one query must contain an aggregation
At least one query must contain an aggregation
At least one query must contain an aggregation
async function query1() {
    let db;
    const client = new MongoClient(uri, { useUnifiedTopology: true });
    try {
        await client.connect();
        db = client.db("Arts");
        const artistsCollection = db.collection("artists");
        const aggregation = [
            { $group: { _id: "$nationality.region", count: { $sum: 1 } } },
            { $sort: { count: -1 } },
        ];
        const res = await artistsCollection
            .aggregate(aggregation)
            .limit(1)
            .toArray();
        console.log(
            "Query 1: The region with the most artists from artists collection is: ",
            res
        );
    } catch (err) {
        console.log("error", err);
    } finally {
        await client.close();
    }
}
async function query1 ( ) { let db ; const client = new MongoClient ( uri , { useUnifiedTopology : true } ) ; try { await client . connect ( ) ; db = client . db ( "Arts" ) ; const artistsCollection = db . collection ( "artists" ) ; const aggregation = [ { $group : { _id : "$nationality.region" , count : { $sum : 1 } } } , { $sort : { count : - 1 } } , ] ; const res = await artistsCollection . aggregate ( aggregation ) . limit ( 1 ) . toArray ( ) ; console . log ( "Query 1: The region with the most artists from artists collection is: " , res ) ; } catch ( err ) { console . log ( "error" , err ) ; } finally { await client . close ( ) ; } }
At least one query must contain an aggregation
At least one query must contain an aggregation