Skip to content

Commit ebeae56

Browse files
committed
fix: throw an error if allowDiskUse is used on MongoDB < 3.2
NODE-2622
1 parent ffc0f55 commit ebeae56

6 files changed

+183
-2
lines changed

lib/operations/find.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const OperationBase = require('./operation').OperationBase;
44
const Aspect = require('./operation').Aspect;
55
const defineAspects = require('./operation').defineAspects;
66
const ReadPreference = require('../read_preference');
7+
const maxWireVersion = require('../core/utils').maxWireVersion;
8+
const MongoError = require('../core/error').MongoError;
79

810
class FindOperation extends OperationBase {
911
constructor(collection, ns, command, options) {
@@ -18,9 +20,13 @@ class FindOperation extends OperationBase {
1820
// copied from `CommandOperationV2`, to be subclassed in the future
1921
this.server = server;
2022

21-
const cursorState = this.cursorState || {};
23+
if (typeof this.cmd.allowDiskUse !== 'undefined' && maxWireVersion(server) < 4) {
24+
callback(new MongoError('The `allowDiskUse` option is not supported on MongoDB < 3.2'));
25+
return;
26+
}
2227

2328
// TOOD: use `MongoDBNamespace` through and through
29+
const cursorState = this.cursorState || {};
2430
server.query(this.ns.toString(), this.cmd, cursorState, this.options, callback);
2531
}
2632
}

test/spec/crud/README.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ Each YAML file has the following keys:
128128
present then use the collection under test.
129129

130130
- ``data``: The data that should exist in the collection after the
131-
operation has been run.
131+
operation has been run, sorted by "_id".
132132

133133
Legacy Test Format for Single Operations
134134
----------------------------------------
@@ -246,6 +246,8 @@ For each test file:
246246

247247
- If the ``outcome`` field is present, assert the contents of the specified
248248
collection using ``globalMongoClient``.
249+
Note the server does not guarantee that documents returned by a find
250+
command will be in inserted order. This find MUST sort by ``{_id:1}``.
249251

250252
Evaluating Matches
251253
------------------
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"runOn": [
3+
{
4+
"maxServerVersion": "3.0.99"
5+
}
6+
],
7+
"collection_name": "test_find_allowdiskuse_clienterror",
8+
"tests": [
9+
{
10+
"description": "Find fails when allowDiskUse true is specified against pre 3.2 server",
11+
"operations": [
12+
{
13+
"object": "collection",
14+
"name": "find",
15+
"arguments": {
16+
"filter": {},
17+
"allowDiskUse": true
18+
},
19+
"error": true
20+
}
21+
],
22+
"expectations": []
23+
},
24+
{
25+
"description": "Find fails when allowDiskUse false is specified against pre 3.2 server",
26+
"operations": [
27+
{
28+
"object": "collection",
29+
"name": "find",
30+
"arguments": {
31+
"filter": {},
32+
"allowDiskUse": false
33+
},
34+
"error": true
35+
}
36+
],
37+
"expectations": []
38+
}
39+
]
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
runOn:
2+
- { maxServerVersion: "3.0.99" }
3+
4+
collection_name: &collection_name 'test_find_allowdiskuse_clienterror'
5+
6+
tests:
7+
-
8+
description: "Find fails when allowDiskUse true is specified against pre 3.2 server"
9+
operations:
10+
-
11+
object: collection
12+
name: find
13+
arguments:
14+
filter: { }
15+
allowDiskUse: true
16+
error: true
17+
expectations: []
18+
-
19+
description: "Find fails when allowDiskUse false is specified against pre 3.2 server"
20+
operations:
21+
-
22+
object: collection
23+
name: find
24+
arguments:
25+
filter: { }
26+
allowDiskUse: false
27+
error: true
28+
expectations: []
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"runOn": [
3+
{
4+
"minServerVersion": "3.2",
5+
"maxServerVersion": "4.3.0"
6+
}
7+
],
8+
"collection_name": "test_find_allowdiskuse_servererror",
9+
"tests": [
10+
{
11+
"description": "Find fails when allowDiskUse true is specified against pre 4.4 server (server-side error)",
12+
"operations": [
13+
{
14+
"object": "collection",
15+
"name": "find",
16+
"arguments": {
17+
"filter": {},
18+
"allowDiskUse": true
19+
},
20+
"error": true
21+
}
22+
],
23+
"expectations": [
24+
{
25+
"command_started_event": {
26+
"command": {
27+
"find": "test_find_allowdiskuse_servererror",
28+
"filter": {},
29+
"allowDiskUse": true
30+
}
31+
}
32+
}
33+
]
34+
},
35+
{
36+
"description": "Find fails when allowDiskUse false is specified against pre 4.4 server (server-side error)",
37+
"operations": [
38+
{
39+
"object": "collection",
40+
"name": "find",
41+
"arguments": {
42+
"filter": {},
43+
"allowDiskUse": false
44+
},
45+
"error": true
46+
}
47+
],
48+
"expectations": [
49+
{
50+
"command_started_event": {
51+
"command": {
52+
"find": "test_find_allowdiskuse_servererror",
53+
"filter": {},
54+
"allowDiskUse": false
55+
}
56+
}
57+
}
58+
]
59+
}
60+
]
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
runOn:
2+
# These tests assert that the driver does not raise client-side errors and
3+
# instead relies on the server to raise an error. Server versions >= 3.2.0
4+
# raise errors for unknown find options, and server versions >= 4.3.1
5+
# support the allowDiskUse option in find.
6+
- { minServerVersion: "3.2", maxServerVersion: "4.3.0" }
7+
8+
collection_name: &collection_name 'test_find_allowdiskuse_servererror'
9+
10+
tests:
11+
-
12+
description: "Find fails when allowDiskUse true is specified against pre 4.4 server (server-side error)"
13+
operations:
14+
-
15+
object: collection
16+
name: find
17+
arguments:
18+
filter: &filter { }
19+
allowDiskUse: true
20+
error: true
21+
expectations:
22+
-
23+
command_started_event:
24+
command:
25+
find: *collection_name
26+
filter: *filter
27+
allowDiskUse: true
28+
-
29+
description: "Find fails when allowDiskUse false is specified against pre 4.4 server (server-side error)"
30+
operations:
31+
-
32+
object: collection
33+
name: find
34+
arguments:
35+
filter: *filter
36+
allowDiskUse: false
37+
error: true
38+
expectations:
39+
-
40+
command_started_event:
41+
command:
42+
find: *collection_name
43+
filter: *filter
44+
allowDiskUse: false

0 commit comments

Comments
 (0)