如何检查Collections.insert()成功插入或不在Meteor? [英] How to check Collections.insert() is Successfully Inserted or not in Meteor?

查看:70
本文介绍了如何检查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
  }
);

请参阅文档了解详情。

这篇关于如何检查Collections.insert()成功插入或不在Meteor?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆