Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Meteor 处理';未定义';流星法中的性质_Meteor_Fullcontact - Fatal编程技术网

Meteor 处理';未定义';流星法中的性质

Meteor 处理';未定义';流星法中的性质,meteor,fullcontact,Meteor,Fullcontact,我在我的Meteor应用程序中创建了一个函数,该函数被设置为“丰富”Meteor集合中包含的数据。该函数用于迭代一个集合,利用提取数据库中维护的所有客户端条目的附加数据(即LinkedIn Bio;员工人数等) 问题在于并非所有数据点都可用于集合中的所有元素(例如,客户端可能没有LinkedIn配置文件)。该函数适用于最初的两个元素,但最终无法抛出TypeError:无法读取未定义的的属性“2”,因为数据变量不包含该公司的LinkedIn配置文件bio(对于此特定示例) 你建议做什么运动?有什么

我在我的Meteor应用程序中创建了一个函数,该函数被设置为“丰富”Meteor集合中包含的数据。该函数用于迭代一个集合,利用提取数据库中维护的所有客户端条目的附加数据(即LinkedIn Bio;员工人数等)

问题在于并非所有数据点都可用于集合中的所有元素(例如,客户端可能没有LinkedIn配置文件)。该函数适用于最初的两个元素,但最终无法抛出
TypeError:无法读取未定义的
的属性“2”,因为
数据变量
不包含该公司的LinkedIn配置文件bio(对于此特定示例)

你建议做什么运动?有什么想法吗?非常感谢您的帮助,我已经为此工作了几个小时

Meteor.methods({
  enrichment() {
    var fullcontact = new FullContact(Meteor.settings.fullContact);
    for (var i = 1; i < customerDb.find({ company: "Qualify" }).count(); i++) {
      var url = customerDb.findOne( { company: "Qualify", 'item.clientId': i.toString() } )['item']['contact_website'];
      var data = fullcontact.company.domain(url);
      if ( data['status'] == 200 ) {
        customerDb.update ({ 
          company: "Qualify", 'item.clientId': i.toString()
        }, {
          $push: {
            bio: data['socialProfiles'][2]['bio'],
            keywords: data['organization']['keywords'],
            employees: data['organization']['approxEmployees'],
            domesticTrafficRank: data['traffic']['topCountryRanking'][0],
            globalTrafficRank: data['traffic']['ranking'][0]
          }
        });
      } else {
        console.log('Data could not be found on the company')
      }
    }
  }
});
Meteor.methods({
浓缩(){
var fullcontact=新的fullcontact(Meteor.settings.fullcontact);
对于(var i=1;i
基于@chazsolo的建议,您可以使用javascript和ORs处理可能丢失的数据和键。这是一种常见的防御性编码模式

这里,如果缺少任何父键或数组元素,则每个项都将替换为空字符串。如果您对可能缺少的内容了解得更多,则可以简化此过程。在某些情况下,您可能需要数字而不是字符串

if ( data['status'] == 200 ) {
  const bio = data['socialProfiles'] && data['socialProfiles'][2] && data['socialProfiles'][2]['bio'] || '';
  const keywords = data['organization'] && data['organization']['keywords'] || '';
  const employees = data['organization'] && data['organization']['approxEmployees'] || '',
  const domesticTrafficRank = data['traffic'] && data['traffic']['topCountryRanking'] && data['traffic']['topCountryRanking'][0] || '',
  const globalTrafficRank = data['traffic'] && data['traffic']['ranking'] && data['traffic']['ranking][0] || '';

  customerDb.update (
    { company: "Qualify", 'item.clientId': i.toString() },
    { $push: { bio, keywords, employees, domesticTrafficRank, globalTrafficRank }}
  });

如果
数据['socialProfiles'][2]
不存在,是什么阻止你仅仅检查是否存在?比如
(数据['socialProfiles'][2]|{})['bio']
?或者你还可以从其他地方获得简历吗?嗨@chazsolo:我想我大致理解你指的是什么-但我试图避免这样一种情况,即我正在构建多个
if(数据类型['socialProfiles']['2']==='undefined'| variable===null){}我方法中的else
语句-我希望得到更干净、更优雅的东西。另外-我不知道如何检查meteor.update函数中的存在性(它会工作吗?)。感谢您的快速回复-感谢您的想法!philipp在处理嵌套属性时,您必须以某种方式检查对象是否存在。您可以在内联(如我上面所建议的)或在调用
customerDb.update
之前执行此操作。这样,您就可以在调用之前构建要推送的对象,这样您就可以得到如下信息:
$push:updatedCustomerData
@chazsolo谢谢您的帮助-这很有意义,我明天会尝试一下(后者),并让您知道!运气好吗?如果你需要一个例子,我很乐意为你提供答案