gpt4 book ai didi

collections - 如何在 Meteor 中检查 Collections.insert() 是否已成功插入?

转载 作者:行者123 更新时间:2023-12-04 17:09:49 25 4
gpt4 key购买 nike

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

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

如何知道上面的插入查询插入成功与否?。因为下面的问题
 If the form details are successfully inserted  - do one action
else -another action

所以请建议我该怎么做?

最佳答案

Insert 在回调函数的参数中提供服务器响应。它提供了两个参数“错误”和“结果”,但根据插入是否成功,其中之一将始终为空。

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
}
);

documentation了解更多信息。

关于collections - 如何在 Meteor 中检查 Collections.insert() 是否已成功插入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21672155/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com