Skip to content

MongoDB Shell

The MongoDB Shell (mongosh) lets you connect to MongoDB to work with your data and configure your database.

Help us improve the MongoDB Shell by posting your ideas and suggestions for improvements.

To report bugs, please use our MONGOSH JIRA project.

1 result found

  1. support try..catch

    It does not appear that mongosh supports try..catch. I put catch block around "insertOne"

    try {
    db.inboxItemCounts.insertOne({
    "_id": {
    "userId": userDoc.userId
    },
    "fromUserSummary": [{
    "userName": fromUserDoc.userName,
    "count": 1
    }],
    "statusSummary": [{
    "status": fromUserDoc.status,
    "count": 1
    }]
    });
    }
    catch(err) {
    // print(err);
    if(err.includes("E11000 duplicate key error collection")) {
    print("got duplicate key exception");
    }
    }

    and the "E11000 duplicate key error collection" exception was not caught at all.
    The script stopped and printed the whole error message.

    1 vote

    We're glad you're here

    Please sign in to leave feedback

    Signed in as (Sign out)

    We’ll send you updates on this idea

    declined  ·  2 comments  ·  Scripting  ·  Admin →
    How important is this to you?

    We're glad you're here

    Please sign in to leave feedback

    Signed in as (Sign out)
  • Don't see your idea?

MongoDB Shell

Categories

Feedback and Knowledge Base