Sunday, June 11, 2017

23/05/2017

                                           MONGODB  NODEJS



SORT

Use the sort() method to sort the result in ascending or descending order.

Use the value -1 in the sort object to sort descending.
        { name: 1 } // ascending
        { name: -1 } // descending


var http = require('http');
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/uki";

MongoClient.connect(url, function(err, db) {
  if (err) throw err;
  var mysort ={name:1};  db.collection("studentsdetails").find().sort(mysort).toArray(function(err, result) {
    if (err) throw err;
    console.log(result);
    db.close();
  });
});





REMOVE


Use the remove() method to delete records, or documents.

var http = require('http');
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/uki";

MongoClient.connect(url, function(err, db) {
  if (err) throw err;
  var myquery = { address: 'Colombo' };  db.collection("studentsdetails").remove(myquery, function(err, obj) {
    if (err) throw err;
    console.log(obj.result.n + " document(s) deleted");
    db.close();
  });
});


Wednesday, June 7, 2017

22/05/2017

                                    MongoDB select from


Select one

var http = require('http');
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/music";

MongoClient.connect(url, function(err, db) {
  if (err) throw err;
  var query = { musicDirector: 'AR Rahman' };
  db.collection("songdetails").find(query).toArray(function(err, result) {
    if (err) throw err;
    console.log(result);
    db.close();
  });
});



sort


var http = require('http');
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/uki";

MongoClient.connect(url, function(err, db) {
  if (err) throw err;
  var mysort = { name: -1 };  db.collection("students").find().sort(mysort).toArray(function(err, result) {
    if (err) throw err;
    console.log(result);
    db.close();
  });
}); 



Remove

var http = require('http');
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/uki";

MongoClient.connect(url, function(err, db) {
  if (err) throw err;
  var myquery = { address: 'Mountain 21' };  db.collection("students").remove(myquery, function(err, obj) {
    if (err) throw err;
    console.log(obj.result.n + " document(s) deleted");
    db.close();
  });
}); 

Tuesday, June 6, 2017

19/05/2017

                                        Nodejs Mongo DB


Create a database

Create a database called "uki":
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/uki";

MongoClient.connect(url, function(err, db) {
  if (err) throw err;
  console.log("Database created!");
  db.close();
});



Create a table

Create a table called "students":
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/uki";

MongoClient.connect(url, function(err, db) {
  if (err) throw err;
  db.createCollection("students", function(err, res) {
    if (err) throw err;
    console.log("Table created!");
    db.close();
  });
}); 
Insert in to table
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/student";

MongoClient.connect(url, function(err, db) {
  if (err) throw err;
  var insert = [
    { name:"mala",maths_marks:45,english_marks:53,science_marks:75},
      { name:"venu",maths_marks:80,english_marks:75,science_marks:85},
        { name:"Kala",maths_marks:32,english_marks:46,science_marks:53},
          { name:"Aruli",maths_marks:78,english_marks:85,science_marks:80},
            { name:"Sharu",maths_marks:80,english_marks:76,science_marks:65},
              { name:"Kumaran",maths_marks:32,english_marks:73,science_marks:84},
                { name:"Lucky",maths_marks:66,english_marks:90,science_marks:45},
                  { name:"Gva",maths_marks:71,english_marks:75,science_marks:56},
                    { name:"Raam",maths_marks:41,english_marks:65,science_marks:88},
  ];
    db.collection("studentmarks").insert(insert, function(err, res) {
      if (err) throw err;
      console.log("Number of records inserted: " + res.insertedCount);
      db.close();
    });
  });
 

18/05/2017

                      Nodejs File System


File System module:
  • Read files
  • Create files
  • Update files
  • Delete files
  • Rename files
  •  
Read a file

The fs.readFile() method is used to read files.


Create files
  • fs.appendFile()
  • fs.open()
  • fs.writeFile()
  Update files
  • fs.appendFile()
  • fs.writeFile()
      Delete files

fs.unlink() 
  

Rename files

fs.rename()









                                                                                             

17/05/2017

                                    NODEJS

What is Node.js?

  • Node.js is an open source server framework
  • Node.js is free
  • Node.js runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)
  • Node.js uses JavaScript on the server

NODEJS MODULE

Consider modules to be the same as JavaScript libraries.

A set of functions you want to include in your application.

To include a module, use the require() function with the name of the module:
       var http = require('http');

Create a own module
you can create your own modules, and easily include them in your applications.
       exports.myDateTime = function () {
    return Date();
};



16/05/2017

                                            MONGODB

  MongoDB is an open-source document database and leading NoSQL database

            MongoDB is a cross-platform, document oriented database that provides, high performance, high availability, and easy scalability. MongoDB works on concept of collection and document.



Advantages of MongoDB over RDBMS

  • Schema less − MongoDB is a document database in which one collection holds different documents. Number of fields, content and size of the document can differ from one document to another.
  • Structure of a single object is clear.
  • No complex joins.
  • Deep query-ability. MongoDB supports dynamic queries on documents using a document-based query language that's nearly as powerful as SQL.
  • Tuning.
  • Ease of scale-out − MongoDB is easy to scale.
  • Conversion/mapping of application objects to database objects not needed.
  • Uses internal memory for storing the (windowed) working set, enabling faster access of data.


     Why Use MongoDB?

  • Document Oriented Storage − Data is stored in the form of JSON style documents.
  • Index on any attribute
  • Replication and high availability
  • Auto-sharding
  • Rich queries
  • Fast in-place updates
  • Professional support by MongoDB

  Where to Use MongoDB?

  • Big Data

  • Content Management and Delivery

  • Mobile and Social Infrastructure

15/05/2017

DATABASE
   A database is a collection of information that is organized so that it can be easily accessed, managed and updated.

1.create a database
 create database databasename; 

2. drop a database
  drop database databasename;

3.create table

create table table_name (
    column1 datatype,
    column2 datatype,
    column3 datatype,
  
);


4.drop table
drop table table_name;

5.alter table
The alter table statement is used to add, delete, or modify columns in an existing table.
     1.alter table table_name
        add column_name datatype; 


     2.alter table table_name
        drop column column_name; 


 
      
 

HTML introduction

HTML stands for Hyper Text Markup Language. HTML describes the structure of web page using markup. HTML elements are the building blo...