Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
MongoDbDriver.__prepareSearchOption(clonedOptions);
// Get first documents from cursor using each
const results = await this.getDatabase()
.collection(this.getCollectionName(entity))
.find(clonedOptions.query)
.limit(clonedOptions.limit)
.skip(clonedOptions.offset)
.sort(clonedOptions.sort)
.toArray();
const totalCount = await this.getDatabase()
.collection(this.getCollectionName(entity))
.countDocuments(clonedOptions.query);
const meta = createPaginationMeta({
totalCount,
page: options.page,
perPage: options.perPage
});
return new QueryResult(results, meta);
}
aggregation: async ({ aggregate, QueryResult }) => {
const pipelines = {
results: pipeline.concat({ $skip: (page - 1) * perPage }, { $limit: perPage }),
totalCount: pipeline.concat({
$count: "count"
})
};
const results = (await aggregate(pipelines.results)) || [];
const totalCount = get(await aggregate(pipelines.totalCount), "0.count") || 0;
const meta = createPaginationMeta({
totalCount,
page,
perPage
});
return new QueryResult(results, meta);
}
});
...pipeline,
{ $project: { _id: -1, id: 1 } },
{ $skip: (page - 1) * perPage },
{ $limit: perPage }
]);
const [totalCount] = await entityClass.getDriver().aggregate(collection, [
...pipeline,
{
$count: "totalCount"
}
]);
return new ListResponse(
await entityClass.find({ sort, query: { id: { $in: ids.map(item => item.id) } } }),
createPaginationMeta({
page,
perPage,
totalCount: totalCount ? totalCount.totalCount : 0
})
);
};
operation: "select",
limit: 10,
offset: 0
});
MySQLDriver.__preparePerPageOption(clonedOptions);
MySQLDriver.__preparePageOption(clonedOptions);
MySQLDriver.__prepareQueryOption(clonedOptions);
MySQLDriver.__prepareSearchOption(clonedOptions);
clonedOptions.calculateFoundRows = true;
const sql = new Select(clonedOptions, entity).generate();
const results = await this.getConnection().query([sql, "SELECT FOUND_ROWS() as count"]);
const meta = createPaginationMeta({
totalCount: results[1][0].count,
page: options.page,
perPage: options.perPage
});
return new QueryResult(results[0], meta);
}