Skip to content

Commit 69d5a2f

Browse files
committed
Make find() in MongoStorageAdapter
1 parent 3a96140 commit 69d5a2f

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/Adapters/Storage/Mongo/MongoCollection.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
let mongodb = require('mongodb');
22
let Collection = mongodb.Collection;
3+
import * as transform from './MongoTransform';
34

45
export default class MongoCollection {
56
_mongoCollection:Collection;
@@ -13,25 +14,28 @@ export default class MongoCollection {
1314
// none, then build the geoindex.
1415
// This could be improved a lot but it's not clear if that's a good
1516
// idea. Or even if this behavior is a good idea.
17+
18+
// Depends on the className and schemaController because mongoObjectToParseObject does.
19+
// TODO: break this dependency
1620
find(query, { skip, limit, sort } = {}) {
1721
return this._rawFind(query, { skip, limit, sort })
18-
.catch(error => {
19-
// Check for "no geoindex" error
20-
if (error.code != 17007 && !error.message.match(/unable to find index for .geoNear/)) {
21-
throw error;
22-
}
23-
// Figure out what key needs an index
24-
let key = error.message.match(/field=([A-Za-z_0-9]+) /)[1];
25-
if (!key) {
26-
throw error;
27-
}
22+
.catch(error => {
23+
// Check for "no geoindex" error
24+
if (error.code != 17007 && !error.message.match(/unable to find index for .geoNear/)) {
25+
throw error;
26+
}
27+
// Figure out what key needs an index
28+
let key = error.message.match(/field=([A-Za-z_0-9]+) /)[1];
29+
if (!key) {
30+
throw error;
31+
}
2832

29-
var index = {};
30-
index[key] = '2d';
31-
return this._mongoCollection.createIndex(index)
32-
// Retry, but just once.
33-
.then(() => this._rawFind(query, { skip, limit, sort }));
34-
});
33+
var index = {};
34+
index[key] = '2d';
35+
return this._mongoCollection.createIndex(index)
36+
// Retry, but just once.
37+
.then(() => this._rawFind(query, { skip, limit, sort }));
38+
})
3539
}
3640

3741
_rawFind(query, { skip, limit, sort } = {}) {

0 commit comments

Comments
 (0)