Posts

Showing posts from March, 2023

Create Data in MongoDB from Python(Jupyter) using PyMongo Drivers

In Anaconda Powershell: pip install pymongo  In Jupyter: Program: import pymongo url='mongodb://localhost:27017/' client=pymongo.MongoClient(url) db1=client['sports'] col1=db1['col11'] doc1={'name':'cricket','level':'international','no':11} col1.insert_one(doc1) doc2={'name':'hockey','level':'national','no':10} col1.insert_one(doc2) doc3={'name':'FootBall','level':'international','no':10} col1.insert_one(doc3) Inserting documents with embedded documents with array fields import pymongo url='mongodb://localhost:27017/' client=pymongo.MongoClient(url) db1=client['sports'] col4 = db1['cricket'] doc4={'name':'cricket','level':'ipl','no':11,'players':{'batsmen':['virat','dhoni','rohit','kl rahul','sky'],'bowlers':['sham...

Express.js with Mongoose

 Program 1:    first.js var express = require ( 'express' ); var app = express (); app . get ( '/greeting' , function ( req , res ){     res . send ( "Hello world!" ); }); app . listen ( 3000 ); npm install --save pug npm install --save body-parser npm install --save multer index.js var express = require ( 'express' ); var bodyParser = require ( 'body-parser' ); var multer = require ( 'multer' ); var upload = multer (); var app = express (); app . get ( '/' , function ( req , res ){     res . render ( 'form' ); }); app . set ( 'view engine' , 'pug' ); app . set ( 'views' , './views' ); // for parsing application/json app . use ( bodyParser . json ()); // for parsing application/xwww- app . use ( bodyParser . urlencoded ({ extended : true })); //form-urlencoded // for parsing multipart/form-data app . use ( upload . array ()); app . use ( express . static ( 'public' ...
 1. MongoDB Architecture Theory p 2. Connection REplication  theory p 3. Data Modelling Theory p 1. design Schema using Advanced Queries    DEMO  p 2. setup the drivers to use MongoDB with your programming language of choice  DEMO 3. build new types of applications for mobile, cloud, e-commerce and  DEMO and social technologies  6/5/ classes 2 classes for practice 4/3

Node.js

  Node.js is an open source server environment Node.js is free Node.js runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.) Node.js uses JavaScript on the server Node.js uses asynchronous programming! Node.js can generate dynamic page content Node.js can create, open, read, write, delete, and close files on the server Node.js can collect form data Node.js can add, delete, modify data in your database What is a Node.js File? Node.js files contain tasks that will be executed on certain events A typical event is someone trying to access a port on the server Node.js files must be initiated on the server before having any effect Node.js files have extension ".js" var  http = require( 'http' ); http. createServer ( function  (req, res) {    res. writeHead ( 200 , { 'Content-Type' :  'text/html' });    res. end ( 'Hello World!' ); }). listen ( 8080 ); save as server1.js and in cmd type node server1.js Open browser and type localhost:8080/...

MongoDB: Operators

List of comparison operators: $cmp, $eq, $gt, $gte, $lt, $lte, and $ne retrieve documents in a collection using Boolean conditions (Query Operators) //AND db.collection.find( { $and: [ { key: value }, { key: value } ] }) //OR db.collection.find( { $or: [ { key: value }, { key: value } ] }) //NOT db.inventory.find( { key: { $not: value } } )  You can use other operators besides $set when updating a document. The $push operator allows you to push a value into an array, in this case we will add a new nickname to the nicknames array. db.people.update({name: 'Tom'}, {$push: {nicknames: 'Tommy'}}) // This adds the string 'Tommy' into the nicknames array in Tom's document. The $pull operator is the opposite of $push, you can pull specific items from arrays. db.people.update({name: 'Tom'}, {$pull: {nicknames: 'Tommy'}}) // This removes the string 'Tommy' from the nicknames array in Tom's document. The $pop operator allows you to remove th...