<commit_before>var Promise = require('bluebird');
var _ = require('lodash');
var parseString = require('xml2js');
var config = require("config");
var log = require('../../logger');
var xml2js = Promise.promisifyAll(parseString);

var collectionName = config.get("dbConfig.mongo.collections")[0].collection;

module.exports = function find(env, query, mongo, options) {
    // If query is not specified, return everything in scope
    if (!query) {
        return Promise.resolve(options.scope);
    }
    var xmlQuery = '<root>' + query + '</root>';
    return xml2js.parseStringAsync(xmlQuery, {explicitArray: false})
        .then(function (queryObject) {
            var fieldsToReturn = getReturnFields(queryObject.root);
            if (fieldsToReturn.length > 0) {
                return _find(options.scope, mongo, fieldsToReturn);
            }
            else {
                return Promise.resolve(options.scope);
            }
        })
}

function _find(ids, mongo, fields) {
    var listingResult = [];
    var resultFields = {};
    _.forEach(fields, function (v) {
        resultFields[v] = 1;
    });
    return Promise.map(ids, function (id) {
        return mongo.find(collectionName, {id: id}, {fields: resultFields})
            .then(function (cursor) {
                cursor.toArrayAsync = Promise.promisify(cursor.toArray, cursor);
                return cursor.toArrayAsync();
            })
            .then(function (docs) {
                var result = {id: id};
                if (docs.length > 0) {
                    for (var i = 0; i < fields.length; i++) {
                        var f = "$" + (i + 1);
                        result[f] = docs[0][fields[i]];
                    }
                }
                log.info("Returned listing details values for %s", id);
                listingResult.push(result);
            })
    }, {
        concurrency: 1
    })
        .then(function () {
            log.info("Returned element values from the listing details for %d apps.",<commit_msg>add missing property name<commit_after>var Promise = require('bluebird');
var _ = require('lodash');
var parseString = require('xml2js');
var config = require("config");
var log = require('../../logger');
var xml2js = Promise.promisifyAll(parseString);

var collectionName = config.get("dbConfig.mongo.collections")[0].collection;

module.exports = function find(env, query, mongo, options) {
    // If query is not specified, return everything in scope
    if (!query) {
        return Promise.resolve(options.scope);
    }
    var xmlQuery = '<root>' + query + '</root>';
    return xml2js.parseStringAsync(xmlQuery, {explicitArray: false})
        .then(function (queryObject) {
            var fieldsToReturn = getReturnFields(queryObject.root);
            if (fieldsToReturn.length > 0) {
                return _find(options.scope, mongo, fieldsToReturn);
            }
            else {
                return Promise.resolve(options.scope);
            }
        })
}

function _find(ids, mongo, fields) {
    var listingResult = [];
    var resultFields = {};
    _.forEach(fields, function (v) {
        resultFields[v] = 1;
    });
    return Promise.map(ids, function (id) {
        return mongo.find(collectionName, {id: id}, {fields: resultFields})
            .then(function (cursor) {
                cursor.toArrayAsync = Promise.promisify(cursor.toArray, cursor);
                return cursor.toArrayAsync();
            })
            .then(function (docs) {
                var result = {id: id, returnAttributes: {}};
                if (docs.length > 0) {
                    for (var i = 0; i < fields.length; i++) {
                        var f = "$" + (i + 1);
                        result.returnAttributes[f] = docs[0][fields[i]];
                    }
                }
                log.info("Returned listing details values for %s", id);
                listingResult.push(result);
            })
    }, {
        concurrency: 1
    })
        .then(function () {
            log.info("Returned element values from the listing details for %d apps.",
{'fraction_non_alphanumeric': 0.13176413491870906, 'fraction_numerical': 0.005338510070371269, 'mean_word_length': 1.9676025917926565, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2623407', 'n_tokens_mistral': 1155, 'n_tokens_neox': 1110, 'n_words': 275}