Skip to content

Commit 33a98bf

Browse files
committed
COMPASS-100: Fix undefined users error: (#509)
When connected to a secondary instance, we ignore the output of the `usersInfo` command if we have executed against a primary with no provided read preference. This pull also fixes the side issues when connected to a secondary of not being able to see the document list.
1 parent 4a137b8 commit 33a98bf

File tree

4 files changed

+40
-12
lines changed

4 files changed

+40
-12
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@
123123
"mongodb": "^2.2.8",
124124
"mongodb-collection-model": "^0.2.3",
125125
"mongodb-connection-model": "5.1.0",
126-
"mongodb-data-service": "1.4.0",
126+
"mongodb-data-service": "1.7.0",
127127
"mongodb-database-model": "^0.1.2",
128128
"mongodb-explain-plan-model": "^0.2.0",
129129
"mongodb-extended-json": "^1.7.0",
130-
"mongodb-instance-model": "^3.1.5",
130+
"mongodb-instance-model": "^3.1.6",
131131
"mongodb-js-metrics": "^1.5.0",
132132
"mongodb-language-model": "^0.3.3",
133133
"mongodb-ns": "^1.0.3",

src/internal-packages/crud/lib/store/load-more-documents-store.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ const Reflux = require('reflux');
44
const app = require('ampersand-app');
55
const NamespaceStore = require('hadron-reflux-store').NamespaceStore;
66
const Action = require('hadron-action');
7+
const ReadPreference = require('mongodb').ReadPreference;
8+
9+
/**
10+
* The default read preference.
11+
*/
12+
const READ = ReadPreference.PRIMARY_PREFERRED;
713

814
/**
915
* The reflux store for loading more documents.
@@ -23,8 +29,8 @@ const LoadMoreDocumentsStore = Reflux.createStore({
2329
* @param {Integer} skip - The number of documents to skip.
2430
*/
2531
loadMoreDocuments: function(skip) {
26-
var filter = app.queryOptions.query.serialize();
27-
var options = { skip: skip, limit: 20, sort: [[ '_id', 1 ]] };
32+
const filter = app.queryOptions.query.serialize();
33+
const options = { skip: skip, limit: 20, sort: [[ '_id', 1 ]], readPreference: READ };
2834
app.dataService.find(NamespaceStore.ns, filter, options, (error, documents) => {
2935
this.trigger(documents);
3036
});

src/internal-packages/crud/lib/store/reset-document-list-store.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@ const Reflux = require('reflux');
44
const app = require('ampersand-app');
55
const NamespaceStore = require('hadron-reflux-store').NamespaceStore;
66
const Action = require('hadron-action');
7-
const metrics = require('mongodb-js-metrics')();
7+
const ReadPreference = require('mongodb').ReadPreference;
8+
9+
/**
10+
* The default read preference.
11+
*/
12+
const READ = ReadPreference.PRIMARY_PREFERRED;
13+
14+
/**
15+
* The default options.
16+
*/
17+
const OPTIONS = { readPreference: READ };
818

919
/**
1020
* The reflux store for resetting the document list.
@@ -25,11 +35,15 @@ const ResetDocumentListStore = Reflux.createStore({
2535
*/
2636
reset: function(filter) {
2737
if (NamespaceStore.ns) {
28-
app.dataService.count(NamespaceStore.ns, filter, {}, (err, count) => {
29-
var options = { limit: 20, sort: [[ '_id', 1 ]] };
30-
app.dataService.find(NamespaceStore.ns, filter, options, (error, documents) => {
31-
this.trigger(documents, count);
32-
});
38+
app.dataService.count(NamespaceStore.ns, filter, OPTIONS, (err, count) => {
39+
if (!err) {
40+
const options = { limit: 20, sort: [[ '_id', 1 ]], readPreference: READ };
41+
app.dataService.find(NamespaceStore.ns, filter, options, (error, documents) => {
42+
if (!error) {
43+
this.trigger(documents, count);
44+
}
45+
});
46+
}
3347
});
3448
}
3549
},

src/internal-packages/schema/lib/store/index.jsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ const Reflux = require('reflux');
33
const StateMixin = require('reflux-state-mixin');
44
const schemaStream = require('mongodb-schema').stream;
55
const _ = require('lodash');
6+
const ReadPreference = require('mongodb').ReadPreference;
7+
8+
/**
9+
* The default read preference.
10+
*/
11+
const READ = ReadPreference.PRIMARY_PREFERRED;
612

713
// stores
814
const NamespaceStore = require('hadron-reflux-store').NamespaceStore;
@@ -113,7 +119,8 @@ const SchemaStore = Reflux.createStore({
113119
maxTimeMS: this.state.maxTimeMS,
114120
query: query,
115121
size: DEFAULT_NUM_DOCUMENTS,
116-
fields: null
122+
fields: null,
123+
readPreference: READ
117124
};
118125

119126
const samplingStart = new Date();
@@ -144,7 +151,8 @@ const SchemaStore = Reflux.createStore({
144151
this.stopSampling();
145152
};
146153

147-
app.dataService.count(ns, query, {maxTimeMS: this.state.maxTimeMS}, (err, count) => {
154+
const countOptions = { maxTimeMS: this.state.maxTimeMS, readPreference: READ };
155+
app.dataService.count(ns, query, countOptions, (err, count) => {
148156
if (err) {
149157
return onError(err);
150158
}

0 commit comments

Comments
 (0)