MongoDB Shell
1 result found
-
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
- Don't see your idea?