Posts

MongoDB

Easier to scale NoSql DBs in general are easier to scale than SQL or relational databases Faster NoSql DBs are also faster in more types of operations. Starting MongoDB after installing it from the MongoDB website using the MSI Run it as an administrator C:\Program Files\MongoDB\Server\3.6\bin>mongod --directoryperdb --dbpath "C:\Program Files\MongoDB\Server\3.6\data\db" --logpath "C:\Program Files\MongoDB\Server\3.6\log\mongo.log" --logappend  --install C:\Program Files\MongoDB\Server\3.6\bin>net start MongoDB The MongoDB service is starting...... How to open a mongo shell? By typing mongo from the bin directory C:\Program Files\MongoDB\Server\3.6\bin>mongo MongoDB shell version v3.6.2 connecting to: mongodb://127.0.0.1:27017 MongoDB server version: 3.6.2 Welcome to the MongoDB shell. Get list of DBs > show dbs admin  0.000GB local  0.000GB Creating own DB > use mycustomers switched to db mycustomers Check current data...

Mongoose with promise

Q) How to configure so that mongoose library uses promises instead of callback? a) Firstly, mongoose library is "imported" using the require('mongoose') statement; var mongoose = require('mongoose'); b) mongoose library has a property that can be assigned with the promise library to be used. c) bluebird is a promise library. d) Import bluebird into your app. var bluebird = require('bluebird'); e) Assign bluebird as the promise library for mongoose. mongoose.promise = bluebird; f)  mongoose.connect is the method that mongoose library uses to connect to a particular mongodb instance. mongoose.connect(config.mongoConnStr, {     promiseLibrary: bluebird }, function (err) {     if (err) throw err;     console.log('Successfully connected to MongoDB using: ' + config.mongoConnStr); }); g) This mongoose.connect method takes three parameters. 1) The connection string 2) A config object which can take various configuration properties ...