📜  mongodb findone - 任何代码示例

📅  最后修改于: 2022-03-11 14:59:31.248000             🧑  作者: Mango

代码示例2
itemsCollection.findOne(query, projection)
  .then(result => {
    if(result) {
      console.log(`Successfully found document: ${result}.`);
    } else {
      console.log("No document matches the provided query.");
    }
    return result;
  })
  .catch(err => console.error(`Failed to find document: ${err}`));