sharedb-mongo 4.1.0 → 4.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +3 -0
- package/package.json +2 -1
- package/test/test_mongo.js +55 -0
package/index.js
CHANGED
|
@@ -1510,17 +1510,20 @@ var cursorOperationsMap = {
|
|
|
1510
1510
|
$count: function(cursor, value, cb) {
|
|
1511
1511
|
cursor.count()
|
|
1512
1512
|
.then(function(result) {
|
|
1513
|
+
cursor.close();
|
|
1513
1514
|
cb(null, result);
|
|
1514
1515
|
}, cb);
|
|
1515
1516
|
},
|
|
1516
1517
|
$explain: function(cursor, verbosity, cb) {
|
|
1517
1518
|
cursor.explain(verbosity)
|
|
1518
1519
|
.then(function(result) {
|
|
1520
|
+
cursor.close();
|
|
1519
1521
|
cb(null, result);
|
|
1520
1522
|
}, cb);
|
|
1521
1523
|
},
|
|
1522
1524
|
$map: function(cursor, fn, cb) {
|
|
1523
1525
|
cursor.map(fn)
|
|
1526
|
+
.toArray()
|
|
1524
1527
|
.then(function(result) {
|
|
1525
1528
|
cb(null, result);
|
|
1526
1529
|
}, cb);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sharedb-mongo",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.1",
|
|
4
4
|
"description": "MongoDB database adapter for ShareDB",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"dependencies": {
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"mongodb6": "npm:mongodb@^6.0.0",
|
|
21
21
|
"nyc": "^14.1.1",
|
|
22
22
|
"ot-json1": "^1.0.1",
|
|
23
|
+
"rich-text": "^4.1.0",
|
|
23
24
|
"sharedb-mingo-memory": "^1.0.0 || ^2.0.0 || ^3.0.0",
|
|
24
25
|
"sinon": "^9.2.4",
|
|
25
26
|
"sinon-chai": "^3.7.0"
|
package/test/test_mongo.js
CHANGED
|
@@ -100,6 +100,61 @@ describe('mongo db', function() {
|
|
|
100
100
|
});
|
|
101
101
|
});
|
|
102
102
|
|
|
103
|
+
it('$map maps docs with output in extra', function(done) {
|
|
104
|
+
var snapshots = [
|
|
105
|
+
{type: 'json0', id: 'test1', v: 1, data: {x: 1, y: 1}},
|
|
106
|
+
{type: 'json0', id: 'test2', v: 1, data: {x: 2, y: 2}},
|
|
107
|
+
{type: 'json0', id: 'test3', v: 1, data: {x: 3, y: 2}}
|
|
108
|
+
];
|
|
109
|
+
var query = {
|
|
110
|
+
y: 2,
|
|
111
|
+
$sort: {x: 1},
|
|
112
|
+
$map: function(doc) {
|
|
113
|
+
return doc.x;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
var db = this.db;
|
|
118
|
+
async.each(snapshots, function(snapshot, cb) {
|
|
119
|
+
db.commit('testcollection', snapshot.id, {v: 0, create: {}}, snapshot, null, cb);
|
|
120
|
+
}, function(err) {
|
|
121
|
+
if (err) return done(err);
|
|
122
|
+
db.query('testcollection', query, null, null, function(err, results, extra) {
|
|
123
|
+
if (err) return done(err);
|
|
124
|
+
|
|
125
|
+
// Since $map can return non-docs, the output is delivered in extra.
|
|
126
|
+
expect(results).eql([]);
|
|
127
|
+
expect(extra).to.deep.equal([2, 3]);
|
|
128
|
+
done();
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('$explain delivers output in extra', function(done) {
|
|
134
|
+
var snapshots = [
|
|
135
|
+
{type: 'json0', id: 'test1', v: 1, data: {x: 1, y: 1}},
|
|
136
|
+
{type: 'json0', id: 'test2', v: 1, data: {x: 2, y: 2}},
|
|
137
|
+
{type: 'json0', id: 'test3', v: 1, data: {x: 3, y: 2}}
|
|
138
|
+
];
|
|
139
|
+
var query = {$explain: true, y: 2};
|
|
140
|
+
|
|
141
|
+
var db = this.db;
|
|
142
|
+
async.each(snapshots, function(snapshot, cb) {
|
|
143
|
+
db.commit('testcollection', snapshot.id, {v: 0, create: {}}, snapshot, null, cb);
|
|
144
|
+
}, function(err) {
|
|
145
|
+
if (err) return done(err);
|
|
146
|
+
db.query('testcollection', query, null, null, function(err, results, extra) {
|
|
147
|
+
if (err) return done(err);
|
|
148
|
+
|
|
149
|
+
expect(results).eql([]);
|
|
150
|
+
// Just check for the presence of an explain result. The specific structure
|
|
151
|
+
// could vary between Mongo versions.
|
|
152
|
+
expect(extra).to.be.an('object');
|
|
153
|
+
done();
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
103
158
|
it('$sort, $skip and $limit should order, skip and limit', function(done) {
|
|
104
159
|
var snapshots = [
|
|
105
160
|
{type: 'json0', v: 1, data: {x: 1}, id: 'test1', m: null},
|