Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saintedlama/mongodb native #256

Merged
merged 47 commits into from
Dec 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
3026b7f
Use mongodb instead of mongodb-core and add minimal test to require m…
saintedlama Oct 8, 2015
54bae03
Fix code style
saintedlama Oct 8, 2015
246976e
Implement basic functionality to insert and remove documents to drive…
saintedlama Oct 8, 2015
ac5c2fc
Fix distinct tests
saintedlama Oct 8, 2015
749dfd7
Implement command execution on collection level
saintedlama Oct 8, 2015
37c2fb5
Test stats
saintedlama Oct 8, 2015
bad1461
Add TODO concerning command interface hits
saintedlama Oct 8, 2015
4257022
Implement find using cursor
saintedlama Oct 8, 2015
b66eb5b
Implement close
saintedlama Oct 8, 2015
482cb84
Implement cursor operations
saintedlama Oct 8, 2015
1df7336
Implement update and getIndexes
saintedlama Oct 8, 2015
d95e6a6
Implement cursor destroy/close
saintedlama Oct 8, 2015
31d98d2
Implement group
saintedlama Oct 8, 2015
180abe8
Implement isCapped
saintedlama Oct 8, 2015
e5a60d1
Implement bulk operations
saintedlama Oct 8, 2015
d461975
Fix code style issues
saintedlama Oct 9, 2015
bae604e
Fix code style issues
saintedlama Oct 9, 2015
73a79ac
Implement aggregations
saintedlama Oct 9, 2015
143c836
Fix next implementation by checking if the cursor was closed and quit…
saintedlama Oct 9, 2015
3a89ec7
Implement passing mongojs connections
saintedlama Oct 9, 2015
60297a3
Implement mongojs and mongodb-native connection passing
saintedlama Oct 9, 2015
48a00df
Add test to verify that connecting to a non existing database yields …
saintedlama Oct 9, 2015
11b513d
Remove destroy event test
saintedlama Oct 13, 2015
cb70b55
Make database an EventEmitter and emit events for error and connect
saintedlama Oct 13, 2015
6e182e3
Test toString implementations for mongos and replica set connection s…
saintedlama Oct 13, 2015
26cc395
Call EventEmitter constructor
saintedlama Oct 13, 2015
f240a7e
Clarify comment
saintedlama Oct 13, 2015
44b8ee8
Introduce _getCollection to avoid duplicate _getConnection + connecti…
saintedlama Oct 13, 2015
bbb030c
Remove duplicate code from aggregate
saintedlama Oct 13, 2015
3d375f8
Generate functions to set limit, batchSize, sort and skip
saintedlama Oct 13, 2015
f49c38e
Cleanup getCollectionNames implementation by using mongodb-native fun…
saintedlama Oct 13, 2015
37c690b
Increase coverage by adding tests for eval, drop database, db stats, …
saintedlama Oct 13, 2015
99811b5
Ignore vi temporary files
saintedlama Nov 30, 2015
0268423
Update dependencies and move to standard version 5
saintedlama Nov 30, 2015
54a9ab9
Fix code style to match standard version 5 code style
saintedlama Nov 30, 2015
d079280
Make checking for err object less verbose
saintedlama Nov 30, 2015
67acfa2
Simplify remove
saintedlama Nov 30, 2015
7b01fa9
Fix checks for insert and
saintedlama Nov 30, 2015
6f5ecd0
Adhere to standard code style
saintedlama Nov 30, 2015
56f1eb8
Implement workaround for harmony proxy in combination with event emit…
saintedlama Nov 30, 2015
f9ab363
Add tests for connection string parsing
saintedlama Dec 1, 2015
3426d64
Add a connection error handler
saintedlama Dec 1, 2015
cb973f0
Fix connection string building for connection strings omitting mongod…
saintedlama Dec 1, 2015
c864aef
Expose NumberLong alias for shell compatibility
saintedlama Dec 1, 2015
ea1b07a
Add tests for mongojs bson type exports
saintedlama Dec 1, 2015
689f161
Correct connecting section
saintedlama Dec 2, 2015
3c59a49
Run geotag update instead of plain geotag in geotag npm script
saintedlama Dec 2, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
.DS_Store
coverage/
*.*~
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,17 @@ var db = mongojs('example.com/mydb', ['mycollection'])
var db = mongojs('username:[email protected]/mydb', ['mycollection'])

// connect using SCRAM-SHA-1 mechanism
var db = mongojs('username:[email protected]/mydb', ['mycollection'], {authMechanism: 'ScramSHA1'})
var db = mongojs('username:[email protected]/mydb?authMechanism=SCRAM-SHA-1', ['mycollection'])

// connect using a different auth source
var db = mongojs('username:[email protected]/mydb?authSource=authdb', ['mycollection'])

// connect now, and worry about collections later
var db = mongojs('mydb')
var mycollection = db.collection('mycollection')
```

__Attention MongoDB 3 users:__ In MongoDB 3 the default auth mechanism is ScramSHA1 not MongoCR (the default auth mechanism in mongojs). When connecting to an auth enabled MongoDB 3 instance providing the authMechanism option value 'ScramSHA1' is mandatory!
[More connection string examples](http://mongodb.github.io/node-mongodb-native/2.0/reference/connecting/authenticating/)

After we connected we can query or update the database just how we would using the mongo API with the exception that we use a callback.
The format for callbacks is always `callback(error, value)` where error is null if no exception has occured. The update methods `save`, `remove`, `update` and `findAndModify` also pass the `lastErrorObject` as the last argument to the callback function.
Expand Down
28 changes: 19 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
var Database = require('./lib/database')
var bson = require('mongodb-core').BSON
var xtend = require('xtend')
var mongodb = require('mongodb')

module.exports = function (connString, cols, options) {
var db = new Database(xtend({connString: connString, cols: cols}, options))
var db = new Database(connString, cols, options)
if (typeof Proxy !== 'undefined') {
var p = Proxy.create({
get: function (obj, prop) {
// Work around for event emitters to work together with harmony proxy
if (prop === 'on' || prop === 'emit') {
return db[prop].bind(db)
}

if (db[prop]) return db[prop]
db[prop] = db.collection(prop)
return db[prop]
Expand All @@ -20,9 +24,15 @@ module.exports = function (connString, cols, options) {
}

// expose bson stuff visible in the shell
module.exports.ObjectId = bson.ObjectId
module.exports.DBRef = bson.DBRef
module.exports.Timestamp = bson.Timestamp
module.exports.MinKey = bson.MinKey
module.exports.MaxKey = bson.MaxKey
module.exports.NumberLong = bson.Long
module.exports.Binary = mongodb.Binary
module.exports.Code = mongodb.Code
module.exports.DBRef = mongodb.DBRef
module.exports.Double = mongodb.Double
module.exports.Long = mongodb.Long
module.exports.NumberLong = mongodb.Long // Alias for shell compatibility
module.exports.MinKey = mongodb.MinKey
module.exports.MaxKey = mongodb.MaxKey
module.exports.ObjectID = mongodb.ObjectID
module.exports.ObjectId = mongodb.ObjectId
module.exports.Symbol = mongodb.Symbol
module.exports.Timestamp = mongodb.Timestamp
24 changes: 0 additions & 24 deletions lib/aggregation-cursor.js

This file was deleted.

15 changes: 7 additions & 8 deletions lib/bulk.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
var mongodb = require('mongodb-core')
var mongodb = require('mongodb')
var each = require('each-series')

var oid = mongodb.BSON.ObjectID.createPk
var oid = mongodb.ObjectID.createPk

var Bulk = function (colName, ordered, onserver, dbname) {
var Bulk = function (colName, ordered, onserver) {
this._colname = colName
this._cmds = []
this._currCmd = null
this._ordered = ordered
this._onserver = onserver
this._dbname = dbname
this._getConnection = onserver

var self = this
this.find = function (query) {
Expand Down Expand Up @@ -145,12 +144,12 @@ Bulk.prototype.execute = function (cb) {
}

this._cmds.push(this._currCmd)
this._onserver(function (err, server) {
this._getConnection(function (err, connection) {
if (err) return cb(err)
each(self._cmds, function (cmd, i, done) {
server.command(self._dbname + '.$cmd', cmd, function (err, res) {
connection.command(cmd, function (err, res) {
if (err) return done(err)
result[cmdkeys[Object.keys(cmd)[0]]] += res.result.n
result[cmdkeys[Object.keys(cmd)[0]]] += res.n
done()
})
}, function (err) {
Expand Down
Loading