Mongodb Mongo collection.insert()失败

Mongodb Mongo collection.insert()失败,mongodb,rest,insert,Mongodb,Rest,Insert,在给出的代码中,执行sendMail函数。但是,不会执行.insert,因为我在数据库中看不到该条目 有人能告诉我怎么解决这个问题吗?谢谢。sendMail应该在insert()函数中调用callback@SarathNair:当然有道理。但这并不能解决插入问题。我在数据库中看不到数据,在回调函数中也看不到错误消息。您是否使用注释的db.close()运行代码?@SarathNair:谢谢。回调函数在与DB的事务完成后调用,而不仅仅是在insert操作之后。现在很好用。 app.post('/'

在给出的代码中,执行sendMail函数。但是,不会执行.insert,因为我在数据库中看不到该条目


有人能告诉我怎么解决这个问题吗?谢谢。

sendMail应该在insert()函数中调用callback@SarathNair:当然有道理。但这并不能解决插入问题。我在数据库中看不到数据,在回调函数中也看不到错误消息。您是否使用注释的db.close()运行代码?@SarathNair:谢谢。回调函数在与DB的事务完成后调用,而不仅仅是在insert操作之后。现在很好用。
app.post('/',function(req,res){
   data= { "name": "xyz",
           "email": "xyz",
           "number":"123",
           "message":"xyz"
   };
   db.collection('messages').insert(data,function(err,result){
      if(err){
         console.log("error in insertion");
      }
      else
         console.log('insertion success');
   });
    /*******************************************
    sendMail(config);
    Find parameters to send the message too
    ********************************************/

    sendMail(true,mailOptions);
    //db.close();
    console.log('Connection with MongoDB is terminated');
});