mongoDb /report

5) MongoDB 

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.

Database

Database is a physical container for collections. Each database gets its own set of files on the file system. A single MongoDB server typically has multiple databases.

Collection

Collection is a group of MongoDB documents. It is the equivalent of an RDBMS table. A collection exists within a single database. Collections do not enforce a schema. Documents within a collection can have different fields. Typically, all documents in a collection are of similar or related purpose.

Document

A document is a set of key-value pairs. Documents have dynamic schema. Dynamic schema means that documents in the same collection do not need to have the same set of fields or structure, and common fields in a collection's documents may hold different types of data.


5.1)

features of mongodb


Rich JSON Documents

  • The most natural and productive way to work with data.

  • Supports arrays and nested objects as values.

  • Allows for flexible and dynamic schemas.

Powerful query language

  • Rich and expressive query language that allows you to filter and sort by any field, no matter how nested it may be within a document.

  • Support for aggregations and other modern use-cases such as geo-based search, graph search, and text search.

  • Queries are themselves JSON, and thus easily composable. No more concatenating strings to dynamically generate SQL queries.

example:

> db.users.find({ "address.zip" : "90404" }) { "_id": "5cf0029caff5056591b0ce7d", "firstname": "Jane", "lastname": "Wu",
"address": { "zip": "90404" } } { "_id": "507f1f77bcf86cd799439011", "firstname": "Jon", "lastname": "Davis",
"address": { "zip": "90404" } } { "_id": "5349b4ddd2781d08c09890f3", "firstname": "Jim", "lastname": "White",
"address": { "zip": "90404" } } { "_id": "5bf142459b72e12b2b1b2cd", "firstname": "Jeff", "lastname": "Taylor",
"address": { "zip": "90404" } } { "_id": "5cf003283b23d04a40d5f88a", "firstname": "Jerry", "lastname": "Miller",
"address": { "zip": "90404" } }

How to connect mongoDb to Node app:
const express =  require('express');
const app = express();
const mongoose = require('mongoose');
const MongoClient = require('mongodb').MongoClient 
const bodyParser = require('body-parser'); 
const session   =  require('express-session');
const flash   = require('connect-flash');
// var MongoStore = require('connect-mongo')(session); 

mongoose.connect('mongodb://localhost:27017/EmployeeDB', {useNewUrlParsertrueuseUnifiedTopologytrue}, (err) => {

     if(mongoose.connect){console.log('Success! MongoDB Connected..')}
     else{console.log('Error in Db connection : ' + err)}
});

mongodb schema:

MongoDB is a great choice for modern applications as it offers a flexible schema design that allows you to meet the ever changing conditions characteristic of Big Data applications. With MongoDB, you can easily store and combine any type of data and dynamically modify schema without experiencing application downtime.

const mongoose = require('mongoose');



const  UserSchema = new mongoose.Schema({


  email : {
        type : String ,
        required : true
    },
  password : {
      type : String ,
      required : true
  }
});


const User   = mongoose.model('User',UserSchema);
module.exports = User;

Comments

Popular posts from this blog

Generative AI Model for text summarization

maintext/ react

Resume description for AI/ ML Developer