Browse Source

Merge branch 'master' into saintedlama/travis-non-legacy

saintedlama/travis-non-legacy
saintedlama 9 years ago
parent
commit
fe378cc4f7
  1. 21
      lib/collection.js
  2. 11
      package.json
  3. 19
      test/test-find-dot-collection.js
  4. 17
      test/test-rename-collection.js

21
lib/collection.js

@ -141,6 +141,17 @@ Collection.prototype.remove = function (query, opts, cb) {
})
}
Collection.prototype.rename = function (name, opts, cb) {
if (typeof opts === 'function') return this.rename(name, {}, opts)
if (!opts) return this.rename(name, {}, noop)
if (!cb) return this.rename(name, noop)
this._getCollection(function (err, collection) {
if (err) return cb(err)
collection.rename(name, opts, cb)
})
}
Collection.prototype.drop = function (cb) {
this.runCommand('drop', cb)
}
@ -189,8 +200,8 @@ Collection.prototype.dropIndex = function (index, cb) {
Collection.prototype.createIndex = function (index, opts, cb) {
if (typeof opts === 'function') return this.createIndex(index, {}, opts)
if (typeof opts === 'undefined') return this.createIndex(index, {}, noop)
if (typeof cb === 'undefined') return this.createIndex(index, opts, noop)
if (!opts) return this.createIndex(index, {}, noop)
if (!cb) return this.createIndex(index, opts, noop)
this._getCollection(function (err, collection) {
if (err) return cb(err)
@ -200,9 +211,9 @@ Collection.prototype.createIndex = function (index, opts, cb) {
}
Collection.prototype.ensureIndex = function (index, opts, cb) {
if (typeof opts === 'function') return this.createIndex(index, {}, opts)
if (typeof opts === 'undefined') return this.createIndex(index, {}, noop)
if (typeof cb === 'undefined') return this.createIndex(index, opts, noop)
if (typeof opts === 'function') return this.ensureIndex(index, {}, opts)
if (!opts) return this.ensureIndex(index, {}, noop)
if (!cb) return this.ensureIndex(index, opts, noop)
this._getCollection(function (err, collection) {
if (err) return cb(err)

11
package.json

@ -6,7 +6,7 @@
"db",
"mongodb"
],
"version": "2.2.1",
"version": "2.3.0",
"repository": "git://github.com/mafintosh/mongojs.git",
"author": "Mathias Buus Madsen <mathiasbuus@gmail.com>",
"license": "MIT",
@ -37,8 +37,8 @@
"xtend": "^4.0.0"
},
"scripts": {
"test": "standard && tape test/test-*.js && node --harmony --harmony-proxies node_modules/tape/bin/tape test/test-*.js",
"cover": "node --harmony --harmony-proxies node_modules/istanbul/lib/cli.js cover node_modules/tape/bin/tape test/test-*.js --report html",
"test": "standard && (tape \"test/test-*.js\" && node --harmony --harmony-proxies node_modules/tape/bin/tape \"test/test-*.js\") | tap-spec",
"cover": "node --harmony --harmony-proxies node_modules/istanbul/lib/cli.js cover node_modules/tape/bin/tape \"test/test-*.js\" --report html",
"geotag": "geopkg update"
},
"devDependencies": {
@ -47,10 +47,11 @@
"istanbul": "^0.4.1",
"shelljs": "^0.5.3",
"standard": "^5.4.1",
"tap-spec": "^4.1.1",
"tape": "^4.0.1"
},
"coordinates": [
48.2287157,
16.3955287
48.2288574,
16.3957216
]
}

19
test/test-find-dot-collection.js

@ -1,16 +1,27 @@
var test = require('./tape')
var mongojs = require('../index')
var db = mongojs('test', ['test.dot'])
var dbNoCollections = mongojs('test')
test('find in dot collection', function (t) {
db['test.dot'].drop(function () {
db['test.dot'].insert({ name: 'dot' }, function (err) {
var collection = db['test.dot']
testDropInsertAndFind(t, collection)
})
test('find in dot collection', function (t) {
var collection = dbNoCollections.collection('test.dot')
testDropInsertAndFind(t, collection)
})
function testDropInsertAndFind (t, collection) {
collection.drop(function () {
collection.insert({ name: 'dot' }, function (err) {
t.error(err)
db['test.dot'].findOne(function (err, doc) {
collection.findOne(function (err, doc) {
t.error(err)
t.equal(doc.name, 'dot')
t.end()
})
})
})
})
}

17
test/test-rename-collection.js

@ -0,0 +1,17 @@
var test = require('./tape')
var mongojs = require('../index')
var db = mongojs('test', ['test123', 'test321'])
test('renameCollection', function (t) {
db.test123.drop(function () {
db.test321.drop(function () {
db.createCollection('test123', function (err) {
t.error(err)
db.test123.rename('test321', function (err) {
t.error(err)
t.end()
})
})
})
})
})
Loading…
Cancel
Save