How do I update values in the documents in my collection in MongoDB

There are 20 documents in my collection, each having the same email address because I made 20 copies of the first document.

I have created a list of mock 20 emails.

I would like to iterate over the documents in my collection and assign each email in my list to the key “email” in each document.

Here is the structure of a document in my collection:

    "_id": {
        "$oid": "62a310f4e43c328922e6f7e2"
    "Name": "Play Boi Roi",
    "Email": "",
    "Password": "Booboo",
    "Questions asked": {
        "$numberInt": "25"
    "Shared posts": {
        "$numberInt": "66"
    "Likes received": {
        "$numberInt": "747"
    "Medals": {
        "Bronze": {
            "$numberInt": "5"
        "Silver": {
            "$numberInt": "8"
        "Gold": {
            "$numberInt": "4"
    "Current courses": ["Computer Systems", "Functional Programming", "Machine Learning", "Chemistry"]

I want to replace “” with an email in my list e.g. [email1, email2, . . . , emailn]

Here is some code I found on MongoDB’s webpage. How do I update this code so it does the required task?

async function listDatabases(client){
    databasesList = await client.db().admin().listDatabases();
    databasesList.databases.forEach(db => console.log(` - ${}`));

const {MongoClient} = require('mongodb');
async function main(){
     * Connection URI. Update <username>, <password>, and <your-cluster-url> to reflect your cluster.
     * See for more details
    const uri = "mongodb+srv://<username>:<password>@f<your-cluster-url>";

    const client = new MongoClient(uri);
    try {
        // Connect to the MongoDB cluster
        await client.connect();
        const db = client.db("MyDatabase");
        const coll = db.collection("MyCollection");
        // Make the appropriate DB calls
        await  listDatabases(client);
    } catch (e) {
    } finally {
        await client.close();


Did you get a chance to look at this?

Sorry, I am not the best resource, I haven’t use mongo in years.