From 7a39b247394a373d57e98830844bf2aecb0eda16 Mon Sep 17 00:00:00 2001 From: Esterling Accime Date: Thu, 25 Oct 2018 18:00:40 -0400 Subject: [PATCH] :memo: update var to const --- README.md | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 6b6498c..26e522b 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,8 @@ 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/). @@ -22,26 +22,26 @@ 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/) @@ -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) @@ -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) @@ -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) { @@ -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'}) @@ -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) @@ -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'}) ``` @@ -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']) }) ```