diff --git a/collection.mongogx.js b/collection.mongogx.js index 538524b..890498f 100644 --- a/collection.mongogx.js +++ b/collection.mongogx.js @@ -146,6 +146,14 @@ OGX.MongogxCollection = class{ If there is shit after any, stop and return that multi nesting find is to do If not supported by mongo (it does't seem to be), then let's not do it (doable but slow, recursions of x arrays) */ + + //if direct prop/val pair, convert to eq + if(typeof(__query[prop]) !== 'object'){ + var f = {}; + f = {eq:__query[prop]}; + __query[prop] = f; + } + base = data[_id]; path = prop.split('.'); if(path.length > 1){ @@ -221,7 +229,10 @@ OGX.MongogxCollection = class{ } return docs; } - + + findOne(__query){ + return this.find(__query, 1); + } //Return as array toJSON(){ diff --git a/core.mongogx.js b/core.mongogx.js index c6e562a..3f136d7 100644 --- a/core.mongogx.js +++ b/core.mongogx.js @@ -249,6 +249,17 @@ OGX.Mongogx = class{ } return false; } + + findOne(__query){ + if(this._isSet()){ + let doc = this.data.db[this.database].getCollection().findOne(__query); + if(this.options.format){ + doc = this._objToArr(doc)[0]; + return doc; + } + } + return false; + } /*INTERNAL STUFF*/ _objToArr(__obj){ @@ -256,7 +267,7 @@ OGX.Mongogx = class{ for(let a in __obj){ if(__obj.hasOwnProperty(a)){ arr.push(__obj[a]); - } + } } return arr; }