1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
/**
* This test ensures that basic eq predicates work with a BinData value.
*/
(function() {
'use strict';
const coll = db.jstests_bindata_find_eq;
function testEqOnlyBinData(subtype, blob, expectedCount) {
assert.eq(expectedCount, coll.find({"a": {$eq: BinData(subtype, blob)}}).itcount());
}
coll.drop();
const docs = [
{a: BinData(0, "AAAAAAAAAAAAAAAAAAAAAAAAAAAA")},
{a: BinData(0, "AQAAAAEBAAVlbl9VSwAAAAAAAAhv")},
{a: BinData(0, "AQAAAAEBAAVlbl9VSwAAAAAAAAhz")},
{a: BinData(0, "////////////////////////////")},
{a: BinData(0, "ZG9n")},
{a: BinData(0, "JA4A8gAxqTwciCuF5GGzAA==")},
{a: BinData(1, "JA4A8gAxqTwciCuF5GGzAA==")},
{a: BinData(0, "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw==")},
{a: BinData(2, "KwAAAFRoZSBxdWljayBicm93biBmb3gganVtcHMgb3ZlciB0aGUgbGF6eSBkb2c=")}
];
assert.commandWorked(coll.insert(docs));
// Test basic queries.
testEqOnlyBinData(0, "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", 1);
testEqOnlyBinData(0, "AQAAAAEBAAVlbl9VSwAAAAAAAAhv", 1);
testEqOnlyBinData(0, "AQAAAAEBAAVlbl9VSwAAAAAAAAhz", 1);
testEqOnlyBinData(0, "////////////////////////////", 1);
testEqOnlyBinData(0, "ZG9n", 1);
testEqOnlyBinData(0, "JA4A8gAxqTwciCuF5GGzAA==", 1);
testEqOnlyBinData(1, "JA4A8gAxqTwciCuF5GGzAA==", 1);
testEqOnlyBinData(0, "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw==", 1);
testEqOnlyBinData(2, "KwAAAFRoZSBxdWljayBicm93biBmb3gganVtcHMgb3ZlciB0aGUgbGF6eSBkb2c=", 1);
// Test BinData records with different subtypes.
const docs2 = [
{a: BinData(1, "AAAAAAAAAAAAAAAAAAAAAAAAAAAA")},
{a: BinData(2, "KwAAAFRoZSBxdWljayBicm93biBmb3gganVtcHMgb3ZlciB0aGUgbGF6eSBkb2c=")},
{a: BinData(3, "OEJTfmD8twzaj/LPKLIVkA==")},
{a: BinData(4, "OEJTfmD8twzaj/LPKLIVkA==")},
{a: BinData(5, "AAAAAAAAAAAAAAAAAAAAAAAAAAAA")},
{a: BinData(6, "AAAAAAAAAAAAAAAAAAAAAAAAAAAA")},
];
assert.commandWorked(coll.insert(docs2));
testEqOnlyBinData(1, "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", 1);
testEqOnlyBinData(2, "KwAAAFRoZSBxdWljayBicm93biBmb3gganVtcHMgb3ZlciB0aGUgbGF6eSBkb2c=", 2);
testEqOnlyBinData(3, "OEJTfmD8twzaj/LPKLIVkA==", 1);
testEqOnlyBinData(4, "OEJTfmD8twzaj/LPKLIVkA==", 1);
testEqOnlyBinData(5, "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", 1);
testEqOnlyBinData(6, "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", 1);
// Test queries with subtypes that yield empty results.
testEqOnlyBinData(8, "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", 0);
testEqOnlyBinData(9, "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", 0);
// Test queries that return nothing.
testEqOnlyBinData(0, "AAAAAAAAAAAAAAAAAAAAAAAAAAAB", 0);
testEqOnlyBinData(0, "", 0);
// Test that we can find multiple docs with the same BinData.
const duplicates = [
{a: BinData(0, "AAAAAAAAAAAAAAAAAAAAAAAAAAAA")},
{a: BinData(0, "AAAAAAAAAAAAAAAAAAAAAAAAAAAA")},
{a: BinData(1, "AAAAAAAAAAAAAAAAAAAAAAAAAAAA")},
{a: BinData(1, "AAAAAAAAAAAAAAAAAAAAAAAAAAAA")}
];
assert.commandWorked(coll.insert(duplicates));
testEqOnlyBinData(0, "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", 3);
testEqOnlyBinData(1, "AAAAAAAAAAAAAAAAAAAAAAAAAAAA", 3);
assert(coll.drop());
})();
|