mongo-control
Advanced tools
Comparing version
@@ -9,2 +9,35 @@ var MongoClient = require('mongodb').MongoClient | ||
MC.createIndex = function (params) { | ||
return new Promise(function (res, err) { | ||
if (!params.db || !params.collection || !params.index) return err('!params.db || !params.collection || !params.index') | ||
if (typeof params.index === 'string') { | ||
try { | ||
params.index = JSON.parse(params.index) | ||
} catch (e) { | ||
err(e) | ||
} | ||
} | ||
if (typeof params.options === 'string') { | ||
try { | ||
params.options = JSON.parse(params.options) | ||
} catch (e) { | ||
err(e) | ||
} | ||
} | ||
MongoClient.connect(params.db, function (e, db) { | ||
if (e) return err(e) | ||
db.collection(params.collection).createIndex (params.index, params.options, function (e, r) { | ||
if (e) return err(e) | ||
res(r) | ||
db.close() | ||
}) | ||
}) | ||
}) | ||
} | ||
MC.ensureIndex = function (params) { | ||
@@ -11,0 +44,0 @@ return new Promise(function (res, err) { |
{ | ||
"name": "mongo-control", | ||
"version": "1.0.43", | ||
"version": "1.0.44", | ||
"description": "Simple functions to control mongo", | ||
@@ -5,0 +5,0 @@ "main": "mongo.control.js", |
23968
3.55%753
3.72%