mongojs / 2.4.0 last updated 3 months ago created on Jun 22nd 2011
Install
npm install --save mongojs
Clone
git clone git@github.com:mafintosh/mongojs.git
dependencies
show all 24
| main |
|
each-series | 1.0.0 | MIT |
|
|
once | 1.3.3 | ISC | |
|
|
parse-mongo-url | 1.1.1 | Apache 2.0 | |
|
|
readable-stream | 2.1.4 | MIT | |
|
|
thunky | 0.1.0 | MIT |
maintainers
versions
86 total
| 2.4.0 | 3 months ago | saintedlama |
| 2.3.0 | 7 months ago | saintedlama |
| 2.2.2 | 8 months ago | saintedlama |
| 2.2.1 | 8 months ago | saintedlama |
| 2.2.0 | 8 months ago | saintedlama |
| 2.1.0 | 8 months ago | saintedlama |
| 2.0.0 | 8 months ago | saintedlama |
| 1.4.1 | 10 months ago | watson |
| 1.4.0 | 10 months ago | watson |
| 1.3.0 | a year ago | saintedlama |
| 1.2.1 | a year ago | watson |
| 1.2.0 | a year ago | watson |
| 1.1.0 | a year ago | saintedlama |
| 1.0.2 | a year ago | watson |
| 1.0.1 | a year ago | sorribas |
| 1.0.0 | a year ago | sorribas |
| 1.0.0-beta4 | a year ago | sorribas |
| 1.0.0-beta3 | a year ago | sorribas |
| 1.0.0-beta2 | a year ago | sorribas |
| 1.0.0-beta1 | a year ago | sorribas |
| 0.18.2 | a year ago | sorribas |
| 0.18.1 | 2 years ago | sorribas |
| 0.18.0 | 2 years ago | sorribas |
| 0.17.0 | 2 years ago | sorribas |
| 0.16.0 | 2 years ago | sorribas |
| 0.15.1 | 2 years ago | sorribas |
| 0.15.0 | 2 years ago | sorribas |
| 0.14.2 | 2 years ago | sorribas |
| 0.14.1 | 2 years ago | sorribas |
| 0.14.0 | 2 years ago | sorribas |
| 0.13.1 | 2 years ago | sorribas |
| 0.13.0 | 2 years ago | sorribas |
| 0.12.1 | 2 years ago | mafintosh |
| 0.12.0 | 2 years ago | sorribas |
| 0.11.1 | 2 years ago | sorribas |
| 0.11.0 | 2 years ago | sorribas |
| 0.10.1 | 2 years ago | mafintosh |
| 0.10.0 | 3 years ago | mafintosh |
| 0.9.11 | 3 years ago | mafintosh |
| 0.9.10 | 3 years ago | mafintosh |
| 0.9.9 | 3 years ago | mafintosh |
| 0.9.8 | 3 years ago | mafintosh |
| 0.9.7 | 3 years ago | mafintosh |
| 0.9.6 | 3 years ago | mafintosh |
| 0.9.5 | 3 years ago | mafintosh |
| 0.9.4 | 3 years ago | mafintosh |
| 0.9.3 | 3 years ago | mafintosh |
| 0.9.2 | 3 years ago | mafintosh |
| 0.9.1 | 3 years ago | mafintosh |
| 0.9.0 | 3 years ago | mafintosh |
| 0.8.1 | 3 years ago | mafintosh |
| 0.8.0 | 3 years ago | mafintosh |
| 0.7.17 | 3 years ago | mafintosh |
| 0.7.16 | 3 years ago | mafintosh |
| 0.7.15 | 3 years ago | mafintosh |
| 0.7.14 | 3 years ago | mafintosh |
| 0.7.13 | 3 years ago | mafintosh |
| 0.7.11 | 3 years ago | mafintosh |
| 0.7.10 | 3 years ago | mafintosh |
| 0.7.9 | 3 years ago | mafintosh |
| 0.7.8 | 3 years ago | mafintosh |
| 0.7.7 | 3 years ago | mafintosh |
| 0.7.6 | 3 years ago | mafintosh |
| 0.7.5 | 3 years ago | mafintosh |
| 0.7.4 | 3 years ago | mafintosh |
| 0.7.3 | 3 years ago | mafintosh |
| 0.7.2 | 3 years ago | mafintosh |
| 0.7.1 | 3 years ago | mafintosh |
| 0.7.0 | 3 years ago | mafintosh |
| 0.6.4 | 3 years ago | mafintosh |
| 0.6.3 | 3 years ago | mafintosh |
| 0.6.2 | 3 years ago | mafintosh |
| 0.6.1 | 4 years ago | mafintosh |
| 0.6.0 | 4 years ago | mafintosh |
| 0.5.1 | 4 years ago | mafintosh |
| 0.5.0 | 4 years ago | mafintosh |
| 0.4.6 | 4 years ago | mafintosh |
| 0.4.5 | 4 years ago | mafintosh |
| 0.4.4 | 4 years ago | mafintosh |
| 0.4.3 | 4 years ago | mafintosh |
| 0.4.2 | 4 years ago | mafintosh |
| 0.4.1 | 4 years ago | mafintosh |
| 0.4.0 | 4 years ago | mafintosh |
| 0.3.2 | 4 years ago | mafintosh |
| 0.3.1 | 4 years ago | ianjorgensen |
| 0.3.0 | 4 years ago | ianjorgensen |
readme
mongojs
A node.js module for mongodb, that emulates the official mongodb API as much as possible. It wraps mongodb-native and is available through npm
Usage
mongojs is easy to use:
The connection string should follow the format described in the mongo connection string docs. Some examples of this could be:
More connection string examples
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.
If you provide a callback to find or any cursor config operation mongojs will call toArray for you
is the same as
For more detailed information about the different usages of update and querying see the mongo docs
Events
Streaming cursors
As of 0.7.0 all cursors are a readable stream of objects.
Notice that you should pipe the cursor through a stringifier (like JSONStream) if you want to pipe it to a serial stream like a http response.
Tailable cursors
If you are using a capped collection you can create a tailable cursor to that collection by adding tailable:true to the find options
Note that you need to explicitly set the selection parameter in the find call.
Database commands
With mongojs you can run database commands just like with the mongo shell using db.runCommand()
or db.collection.runCommand()
Bulk updates
As of 0.15 mongojs supports the Bulk updates introduced in mongodb 2.6. Here's an example of the usage
Replication Sets
Mongojs can also connect to a mongo replication set by providing a connection string with multiple hosts
For more detailed information about replica sets see the mongo replication docs
Using harmony features
If you run node.js with the --harmony option, then you can ommit the collection names array, and you can do stuff like.
In the above example the hackers collection is enabled automagically (similar to the shell) using the Proxy feature in harmony
Passing a DB to the constructor
If you have an instance of mongojs, you can pass this to the constructor and mongojs will use the existing connection of that instance instead of creating a new one.
Features not supported for MongoDB 2.4 or older (on mongojs version 1.0+).
- Index creation and deletion
- Aggregation cursors.
This features are relatively easy to add, but would make the code unnecessarily more complex. If you are using mongodb 2.4 or older and would like to use mongojs 1.0 with the above mentioned feautres, feel free to make a pull request or open and issue..
Upgrading from 0.x.x to 1.2.x
Version > 1.0.x is a major rewrite of mongojs. So expect some things not to work the same as in mongojs 0.x.x versions. Breaking changes include:
- Removed
mongojs.connectusemongojs()directly instead
API
This API documentation is a work in progress.
Collection
db.collection.aggregate([pipeline], [options], [callback])
https://docs.mongodb.org/manual/reference/method/db.collection.aggregate/
db.collection.aggregate([pipelineStep], [pipelineStep], [pipelineStep], ..., [callback])
db.collection.count([query], callback)
db.collection.createIndex(keys, options, [callback])
db.collection.distinct(field, query, callback)
db.collection.drop([callback])
db.collection.dropIndex(index, [callback])
db.collection.dropIndexes([callback])
db.collection.ensureIndex(keys, options, [callback])
db.collection.find([criteria], [projection], [callback])
This function applies a query to a collection. You can get the return value, which is a cursor, or pass a callback
as the last parameter. Said callback receives (err, documents)
db.collection.findOne([criteria], [projection], callback)
Apply a query and get one single document passed as a callback. The callback receives (err, document)
db.collection.findAndModify(document, callback)
db.collection.getIndexes(callback)
db.collection.group(document, callback)
db.collection.insert(docOrDocs, [callback])
db.collection.isCapped(callback)
db.collection.mapReduce(map, reduce, options, [callback])
db.collection.reIndex([callback])
db.collection.remove(query, [justOne], [callback])
db.collection.remove(query, [options], [callback])
db.collection.runCommand(command, [callback])
db.collection.save(doc, [options], [callback])
db.collection.stats(callback)
db.collection.update(query, update, [options], [callback])
db.collection.toString()
Get the name of the collection.