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

📝 update var to const #361

Merged
merged 1 commit into from
Oct 20, 2019
Merged
Changes from all commits
Commits
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
40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,35 @@ It wraps [mongodb-native](https://github.com/christkv/node-mongodb-native) and i
mongojs is easy to use:

```js
var mongojs = require('mongojs')
var db = mongojs(connectionString, [collections])
const mongojs = require('mongojs')
const db = mongojs(connectionString, [collections])
```

The connection string should follow the format described in [the mongo connection string docs](http://docs.mongodb.org/manual/reference/connection-string/).
Some examples of this could be:

```js
// simple usage for a local db
var db = mongojs('mydb', ['mycollection'])
const db = mongojs('mydb', ['mycollection'])

// the db is on a remote server (the port default to mongo)
var db = mongojs('example.com/mydb', ['mycollection'])
const db = mongojs('example.com/mydb', ['mycollection'])

// we can also provide some credentials
var db = mongojs('username:password@example.com/mydb', ['mycollection'])
const db = mongojs('username:password@example.com/mydb', ['mycollection'])

// connect using SCRAM-SHA-1 mechanism
var db = mongojs('username:password@example.com/mydb?authMechanism=SCRAM-SHA-1', ['mycollection'])
const db = mongojs('username:password@example.com/mydb?authMechanism=SCRAM-SHA-1', ['mycollection'])

// connect using a different auth source
var db = mongojs('username:password@example.com/mydb?authSource=authdb', ['mycollection'])
const db = mongojs('username:password@example.com/mydb?authSource=authdb', ['mycollection'])

// connect with options
var db = mongojs('username:password@example.com/mydb', ['mycollection'], { ssl: true })
const db = mongojs('username:password@example.com/mydb', ['mycollection'], { ssl: true })

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

[More connection string examples](http://mongodb.github.io/node-mongodb-native/2.0/reference/connecting/)
Expand Down Expand Up @@ -116,7 +116,7 @@ For more detailed information about the different usages of update and querying
## Events

```js
var db = mongojs('mydb', ['mycollection'])
const db = mongojs('mydb', ['mycollection'])

db.on('error', function (err) {
console.log('database error', err)
Expand All @@ -133,7 +133,7 @@ db.on('connect', function () {
As of `0.7.0` all cursors are a [readable stream](http://nodejs.org/api/stream.html#stream_readable_stream) of objects.

```js
var JSONStream = require('JSONStream')
const JSONStream = require('JSONStream')

// pipe all documents in mycollection to stdout
db.mycollection.find({}).pipe(JSONStream.stringify()).pipe(process.stdout)
Expand All @@ -147,7 +147,7 @@ if you want to pipe it to a serial stream like a http response.
If you are using a capped collection you can create a [tailable cursor](http://docs.mongodb.org/manual/tutorial/create-tailable-cursor/) to that collection by adding `tailable:true` to the find options

```js
var cursor = db.mycollection.find({}, {}, {tailable: true, timeout: false})
const cursor = db.mycollection.find({}, {}, {tailable: true, timeout: false})

// since all cursors are streams we can just listen for data
cursor.on('data', function (doc) {
Expand Down Expand Up @@ -180,7 +180,7 @@ db.things.runCommand('count', function (err, res) {
As of 0.15 mongojs supports the Bulk updates introduced in mongodb 2.6. Here's an example of the usage

```js
var bulk = db.a.initializeOrderedBulkOp()
const bulk = db.a.initializeOrderedBulkOp()
bulk.find({type: 'water'}).update({$set: {level: 1}})
bulk.find({type: 'water'}).update({$inc: {level: 2}})
bulk.insert({name: 'Spearow', type: 'flying'})
Expand All @@ -200,7 +200,7 @@ bulk.execute(function (err, res) {
Mongojs can also connect to a mongo replication set by providing a connection string with multiple hosts

```js
var db = mongojs('rs-1.com,rs-2.com,rs-3.com/mydb?slaveOk=true', ['mycollection'])
const db = mongojs('rs-1.com,rs-2.com,rs-3.com/mydb?slaveOk=true', ['mycollection'])
```

For more detailed information about replica sets see [the mongo replication docs](http://www.mongodb.org/display/DOCS/Replica+Sets)
Expand All @@ -210,8 +210,8 @@ For more detailed information about replica sets see [the mongo replication docs
If you run node.js with the `--harmony` option, then you can ommit the collection names array, and you can do stuff like.

```js
var mongojs = require('mongojs')
var db = require('mydb')
const mongojs = require('mongojs')
const db = require('mydb')

db.hackers.insert({name: 'Ed'})
```
Expand All @@ -224,11 +224,11 @@ If you have an instance of mongojs, you can pass this to the constructor and mon
existing connection of that instance instead of creating a new one.

```js
var mongodb = require('mongodb')
var mongojs = require('mongojs')
const mongodb = require('mongodb')
const mongojs = require('mongojs')

mongodb.Db.connect('mongodb://localhost/test', function (err, theDb) {
var db = mongojs(theDb, ['myCollection'])
const db = mongojs(theDb, ['myCollection'])
})
```

Expand Down