2016-04-22 33 views

回答

0

只需使用嘗試捕捉

try { 
db.products.insertOne(
    { "item": "envelopes", "qty": 100, type: "Self-Sealing" }, 
    { writeConcern: { w : "majority", wtimeout : 100 } } 
); 
} catch (e) { 
    print (e); 
} 

它將捕獲異常。