如何检查Collections.insert()成功插入或不在Meteor?

问题描述:

如何检查(用户创建的集合)Collections.insert()已成功插入或不在 Meteor JS ?.例如,我使用客户端集合插入细节,如下所示:

How to check(user created collections) Collections.insert() is Successfully Inserted or not in Meteor JS?. For example I am using the Client Collections to insert details as shown below:

Client.insert({ name: "xyz", userid: "1", care:"health" });

如何知道上面的插入查询是否成功插入?由于以下问题

How to know the above insert query is successfully inserted or not?. Because of the below problem

 If the form details are successfully inserted  - do one action
  else -another action

那么请建议我该怎么办?

So Please suggest me what to do?

Insert在回调函数的参数中提供了一个服务器响应。它提供了两个参数'error'和'result',但是其中一个将总是null,这取决于插入是否成功。

Insert provides a server response in the arguments to a callback function. It provides two arguments 'error' and 'result' but one of them will always be null depending on whether the insert is successful.

Client.insert( { name: "xyz", userid: "1", care:"health" }
  , function( error, result) { 
    if ( error ) console.log ( error ); //info about what went wrong
    if ( result ) console.log ( result ); //the _id of new object if successful
  }
);

请参阅文档了解详情。