Category Archive: MongoDB

Jul 16

MongoDB Examples – 4 : Reading from MongoDB

//Install express first //npm install express   var express = require(‘express’); var app = express(); const MongoClient = require(‘mongodb’).MongoClient; let db; MongoClient.connect(‘mongodb://localhost/issuetracker’).then(connection => { db = connection; app.listen(3000, () => { console.log(‘App started on port 3000’); }); }).catch(error => { console.log(‘ERROR:’, error); });   app.get(‘/api/issues’, (req, res) => { db.collection(‘issues’).find().toArray().then(issues => { const metadata = …

Continue reading »

Jul 16

MongoDB Examples – 3: NodeJS, MongoDB: CallBacks, Promises, Generators, Async

Create the Script File: nano trymongo.js Put the content ‘use strict’; const MongoClient = require(‘mongodb’); function usage() { console.log(‘Usage:’); console.log(‘node’, __filename, ‘<option>’); console.log(‘Where option is one of:’); console.log(‘ callbacks Use the callbacks paradigm’); console.log(‘ promises Use the Promises paradigm’); console.log(‘ generator Use the Generator paradigm’); console.log(‘ async Use the async module’); } if (process.argv.length < …

Continue reading »

Jul 16

MongoDb Examples – 2 : Schema Initialization

Create a Mongo Script and Populate with some data:   Create: nano init.mongo.js  (in Linux or MacOs)   Put content in the script file:   db = new Mongo().getDB(‘issuetracker’); db.issues.remove({}); db.issues.insert([ { status: ‘Open’, owner: ‘Ravan’, created: new Date(‘2016-08-15’), effort: 5, completionDate: undefined, title: ‘Error in console when clicking Add’, }, { status: ‘Assigned’, owner: …

Continue reading »

Jul 16

MongoDB Examples – 1

mongod -> to run the server mongo -> to run Mongo Shell db-> to see current/selected/in-use database name use playground -> create or change database (playground) show databases -> see all databases show collections -> see the collections (employees for example) in current database Insert one Record/data db.employees.insert({name: {first: ‘John’, last: ‘Doe’}, age: 44});   …

Continue reading »

Aug 22

How to Install and Use MongoDB on Windows Platforms such as Windows 7 or Windows 10

How to Install and Use MongoDB on Windows Platforms such as Windows 7 or Windows 10

%d bloggers like this:
Skip to toolbar
dead