Skip to content
This repository was archived by the owner on May 17, 2021. It is now read-only.

Commit a2f040f

Browse files
authored
COMPASS-971: Add cursor option to aggregate (#60)
1 parent cc6b9a9 commit a2f040f

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

lib/fetch.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,9 @@ var _ = require('lodash');
88
var async = require('async');
99
var mongodbNS = require('mongodb-ns');
1010
var isNotAuthorizedError = require('mongodb-js-errors').isNotAuthorized;
11-
var ReadPreference = require('mongodb').ReadPreference;
1211

1312
var debug = require('debug')('mongodb-index-model:fetch');
1413

15-
/**
16-
* The default read preference.
17-
*/
18-
var READ = ReadPreference.PRIMARY_PREFERRED;
19-
2014
/**
2115
* helper function to attach objects to the async.auto task structure.
2216
* @param {any} anything pass in any variable to attach it to the name
@@ -34,7 +28,7 @@ function attach(anything, done) {
3428
function getIndexes(done, results) {
3529
var db = results.db;
3630
var ns = mongodbNS(results.namespace);
37-
db.db(ns.database, {readPreference: {mode: READ}, returnNonCachedInstance: true}).collection(ns.collection).indexes(function(err, indexes) {
31+
db.db(ns.database, { returnNonCachedInstance: true }).collection(ns.collection).indexes(function(err, indexes) {
3832
if (err) {
3933
done(err);
4034
}
@@ -58,8 +52,8 @@ function getIndexStats(done, results) {
5852
{ $indexStats: { } },
5953
{ $project: { name: 1, usageHost: '$host', usageCount: '$accesses.ops', usageSince: '$accesses.since' } }
6054
];
61-
var collection = db.db(ns.database, {readPreference: {mode: READ}, returnNonCachedInstance: true}).collection(ns.collection);
62-
collection.aggregate(pipeline, function(err, res) {
55+
var collection = db.db(ns.database, { returnNonCachedInstance: true }).collection(ns.collection);
56+
collection.aggregate(pipeline, { cursor: {}}).toArray(function(err, res) {
6357
if (err) {
6458
if (isNotAuthorizedError(err)) {
6559
/**
@@ -92,7 +86,7 @@ function getIndexStats(done, results) {
9286
function getIndexSizes(done, results) {
9387
var db = results.db;
9488
var ns = mongodbNS(results.namespace);
95-
db.db(ns.database, {readPreference: {mode: READ}, returnNonCachedInstance: true}).collection(ns.collection).stats(function(err, res) {
89+
db.db(ns.database, { returnNonCachedInstance: true }).collection(ns.collection).stats(function(err, res) {
9690
if (err) {
9791
if (isNotAuthorizedError(err)) {
9892
debug('Not authorized to get collection stats. Returning default for indexSizes {}.');

0 commit comments

Comments
 (0)