Tag: 嵌套的

node.js嵌套async.eachSeries

我刚刚进入节点,并结束了新的async.js。 我不确定我想做的事情是可行的(猜测是这样),还是我的做法是正确的(猜测不是)。 这是事情: 这个代码是pipe理一些instagram数据,所以我会根据代码实际需要做的事情来解释一切,以便更容易理解。 连接到mongoDB,得到一些Instagram帐户ID(完成) 为每个ID我想获得拉斯维加斯10个职位(我已经保存在我的数据库中)。 对于每个帐户的10个项目,我需要获得(评论+喜欢)的总和,并将该值与第一个eachSeries调用的out代码相比较。 router.get('/users_all', function(req, res) { User.find().sort({'counts.followed_by': 'descending'}).exec(function(err, users) { async.eachSeries(users, function(item, outerCallback) { Media.find({'userId': item.user_id}).exec(function(err, medias) { var count = 0; async.eachSeries(medias, function(item, outerCallback2) { count += item.comments_count + item.likes_count; }); }); item.totalAmount = count; }); res.json(users); }); } 我只是没有设置callback每个eachSeries,因为我不知道把它们放在哪里,我认为我的代码更容易理解这种方式。 如果需要更多关于代码请求的澄清。 谢谢你的帮助。

Mongoose:查找并过滤嵌套的数组

我试图用Find()命令Find()整个文档,并用条件筛选嵌套数组。 这里使用了一个Schema: var ListSH = new Schema({ name: { type: String, unique: true, required: true}, subject : String, recipients : [ Schema({ uid : { type : ObjectId, required : true, ref:'User', unique: true}, status : { type : Number, default : 1 } },{_id: false}) ] }; 目前我做ListModel.findOne({ _id : req.params.id_list, function(err,list){…}; 邮差给我: { […]

使用async.js进行asynchronous树遍历

我试图使用async.js遍历一个嵌套的项目树。 遍历一个分支后,遍历终止。 var count=0; exports.buildFamily = function(item_id, mback){ var extendedFamily={}; exports.getItembyId(item_id, function(err, item){ extendedFamily=item; if(item.descendants){ extendedFamily.kids=[]; count=+item.descendants.length; console.log('outercount ' + count); async.eachSeries(item.descendants, function(item){ count– console.log('item: ' + item) exports.buildFamily(item, function(err, family){ console.log('deepcount: ' + count); extendedFamily.kids.push(family); if(count===0){ return mback(null, extendedFamily);} else {extendedFamily.kids.push(family);} }) }) } else{ if(count===0){ return mback(null, extendedFamily);} else{ extendedFamily.kids.push(family); return; } } […]