Skip to content

Commit

Permalink
Merge pull request Countly#2153 from Cookiezaurs/master
Browse files Browse the repository at this point in the history
Bugfix. Exported file do not limit users on query: Recieved message is #.
  • Loading branch information
ar2rsawseen authored Nov 23, 2021
2 parents a4e84fc + 4561fc5 commit 134d3be
Showing 1 changed file with 43 additions and 36 deletions.
79 changes: 43 additions & 36 deletions api/parts/data/exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,45 +441,52 @@ exports.fromDatabase = function(options) {
}
alternateName += "_exported_on_" + moment().format("DD-MMM-YYYY");
options.filename = options.filename || alternateName;
plugin.dispatch("/drill/preprocess_query", {
query: options.query
});

var cursor = options.db.collection(options.collection).find(options.query, {"projection": options.projection});
if (options.sort) {
cursor.sort(options.sort);
}
if (options.limit) {
cursor.limit(parseInt(options.limit));
}
if (options.skip) {
cursor.skip(parseInt(options.skip));
if (options.collection.startsWith("app_users")) {
options.params.qstring.method = "user_details";
options.params.app_id = options.collection.replace("app_users", "");
}
plugin.dispatch("/drill/preprocess_query", {
query: options.query,
params: options.params
}, ()=>{
var cursor = options.db.collection(options.collection).find(options.query, {"projection": options.projection});
if (options.sort) {
cursor.sort(options.sort);
}
if (options.limit) {
cursor.limit(parseInt(options.limit));
}
if (options.skip) {
cursor.skip(parseInt(options.skip));
}

if (options.type === "stream" || options.type === "json") {
options.output = options.output || function(stream) {
exports.stream(options.params, stream, options);
};
cursor.stream({
transform: function(doc) {
doc = transformValuesInObject(doc, options.mapper);
return JSON.stringify(doc);
}
});
options.output(cursor);
}
else if (options.type === "xls" || options.type === "xlsx" || options.type === "csv") {
options.output = options.output || function(stream) {
exports.stream(options.params, stream, options);
};
cursor.stream();
options.output(cursor);
}
else {
cursor.toArray(function(err, data) {
exports.fromData(data, options);
});
}
if (options.type === "stream" || options.type === "json") {
options.output = options.output || function(stream) {
exports.stream(options.params, stream, options);
};
cursor.stream({
transform: function(doc) {
doc = transformValuesInObject(doc, options.mapper);
return JSON.stringify(doc);
}
});
options.output(cursor);
}
else if (options.type === "xls" || options.type === "xlsx" || options.type === "csv") {
options.output = options.output || function(stream) {
exports.stream(options.params, stream, options);
};
cursor.stream();
options.output(cursor);
}
else {
cursor.toArray(function(err, data) {
exports.fromData(data, options);
});
}

});
};

/**
Expand Down

0 comments on commit 134d3be

Please sign in to comment.