From fe8160449cac0eec253715cbfe2b95c58d1d84af Mon Sep 17 00:00:00 2001 From: Drew Gross Date: Mon, 23 May 2016 11:54:54 -0700 Subject: [PATCH] Revert changes to find --- src/Adapters/Storage/Mongo/MongoCollection.js | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/src/Adapters/Storage/Mongo/MongoCollection.js b/src/Adapters/Storage/Mongo/MongoCollection.js index e3092818..bf41582b 100644 --- a/src/Adapters/Storage/Mongo/MongoCollection.js +++ b/src/Adapters/Storage/Mongo/MongoCollection.js @@ -1,6 +1,5 @@ let mongodb = require('mongodb'); let Collection = mongodb.Collection; -import * as transform from './MongoTransform'; export default class MongoCollection { _mongoCollection:Collection; @@ -14,28 +13,25 @@ export default class MongoCollection { // none, then build the geoindex. // This could be improved a lot but it's not clear if that's a good // idea. Or even if this behavior is a good idea. - - // Depends on the className and schemaController because mongoObjectToParseObject does. - // TODO: break this dependency find(query, { skip, limit, sort } = {}) { return this._rawFind(query, { skip, limit, sort }) - .catch(error => { - // Check for "no geoindex" error - if (error.code != 17007 && !error.message.match(/unable to find index for .geoNear/)) { - throw error; - } - // Figure out what key needs an index - let key = error.message.match(/field=([A-Za-z_0-9]+) /)[1]; - if (!key) { - throw error; - } + .catch(error => { + // Check for "no geoindex" error + if (error.code != 17007 && !error.message.match(/unable to find index for .geoNear/)) { + throw error; + } + // Figure out what key needs an index + let key = error.message.match(/field=([A-Za-z_0-9]+) /)[1]; + if (!key) { + throw error; + } - var index = {}; - index[key] = '2d'; - return this._mongoCollection.createIndex(index) - // Retry, but just once. - .then(() => this._rawFind(query, { skip, limit, sort })); - }) + var index = {}; + index[key] = '2d'; + return this._mongoCollection.createIndex(index) + // Retry, but just once. + .then(() => this._rawFind(query, { skip, limit, sort })); + }); } _rawFind(query, { skip, limit, sort } = {}) {