1
1
let mongodb = require ( 'mongodb' ) ;
2
2
let Collection = mongodb . Collection ;
3
+ import * as transform from './MongoTransform' ;
3
4
4
5
export default class MongoCollection {
5
6
_mongoCollection :Collection ;
@@ -13,25 +14,28 @@ export default class MongoCollection {
13
14
// none, then build the geoindex.
14
15
// This could be improved a lot but it's not clear if that's a good
15
16
// 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
16
20
find ( query , { skip, limit, sort } = { } ) {
17
21
return this . _rawFind ( query , { skip, limit, sort } )
18
- . catch ( error => {
19
- // Check for "no geoindex" error
20
- if ( error . code != 17007 && ! error . message . match ( / u n a b l e t o f i n d i n d e x f o r .g e o N e a r / ) ) {
21
- throw error ;
22
- }
23
- // Figure out what key needs an index
24
- let key = error . message . match ( / f i e l d = ( [ A - Z a - 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 ( / u n a b l e t o f i n d i n d e x f o r .g e o N e a r / ) ) {
25
+ throw error ;
26
+ }
27
+ // Figure out what key needs an index
28
+ let key = error . message . match ( / f i e l d = ( [ A - Z a - z _ 0 - 9 ] + ) / ) [ 1 ] ;
29
+ if ( ! key ) {
30
+ throw error ;
31
+ }
28
32
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
+ } )
35
39
}
36
40
37
41
_rawFind ( query , { skip, limit, sort } = { } ) {
0 commit comments