Skip to content
This repository was archived by the owner on Feb 4, 2022. It is now read-only.

Commit 23ace85

Browse files
committed
refactor(read-preference): support legacy non-array for tags
To prevent breaking changes, we will still support passing in tags as an object rather than the documented required array. This will change in 4.x
1 parent d9c5c16 commit 23ace85

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

Diff for: lib/topologies/read_preference.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,20 @@
4141
* @return {ReadPreference}
4242
*/
4343
const ReadPreference = function(mode, tags, options) {
44-
if (tags && !Array.isArray(tags) && typeof tags === 'object')
45-
(options = tags), (tags = undefined);
44+
// TODO(major): tags MUST be an array of tagsets
45+
if (tags && !Array.isArray(tags)) {
46+
console.warn(
47+
'ReadPreference tags must be an array, this will change in the next major version'
48+
);
49+
50+
if (typeof tags.maxStalenessSeconds !== 'undefined') {
51+
// this is likely an options object
52+
options = tags;
53+
tags = undefined;
54+
} else {
55+
tags = [tags];
56+
}
57+
}
4658

4759
this.mode = mode;
4860
this.tags = tags;

0 commit comments

Comments
 (0)