Monday 31 March 2014

how to get the specific record from nested array in mongoDB using nodeJS

db.collectionName.aggregate({"$unwind": "$nestedArrayColumnName"}, {"$match": {"columnWhereCond": arr[i]}}, {"$project": {"_id": 0, "columnToGet": 1}}, function(err2, rows) {
                for (var i = 0; i < rows.length; i++) {
                     var obj = rows[i];
                    for (var key in obj)
                    {
                        var attrName = key;
                        var attrValue = obj[key];
                        columnVal = attrValue['name'];
                    }
                }
});

No comments:

Post a Comment