RESTful CRUD APIs using Node.js Base Structure Mongoose is an Object Data Modeling (ODM) library for MongoDB and Node.js. It manages relationships between data, provides
Category: MongoDB
MongoDB is a free and open-source cross-platform document-oriented database program.
Different Way Mongoose Connection
https://stackoverflow.com/questions/37695147/connect-mongo-creating-new-session-every-second var express = require(‘express’); var fs = require(‘fs’); var mongoose = require(‘mongoose’); var passport = require(‘passport’); var flash = require(‘connect-flash’); var morgan = require(‘morgan’);
CRUD Mongoose
CRUD Mongoose : https://zellwk.com/blog/mongoose/ Connecting to a database First, you need to download Mongoose. npm install mongoose –save You can connect to a database with
Convert date to MongoDB ISODate format in JavaScript using Moment JS
uses ISODate as their primary date type. If you want to insert a date object into a MongoDB collection, you can use the Date() shell
Mongoose Plugin
What We Will Cover Plug-ins Middleware Hooks Discriminators Promises Main Take-away – MongoDB is “schema-less” – Everything in Mongoose starts with a Schema Schema –
MongoDb – Query for Array Element
db.Posts.insert({ PostBy: “Pankaj Choudhary”, Time:new Date(), Title:”MonogoDB Day2″, Tags:[ “NoSQL”, “MonogoDB”, “Database”, “SQL” ], Likes:3, Comment: [ { CommentBY : “Sanjeev”, Text: “Nice Show” },{
MongoDb – Tips
MongoDB Data Types Object This data type stores embedded documents. When a document contains another document in the form of key-value pair then such type
MonogDb – Index
Index Overview Index Creation Process B-Tree and how index works Default _id index with ObjectID getIndexes() Create new index – Which Fields should be added
MongoDB Aggregation 02
db.Persons.aggregate([ {$project: {isActive: 1, name:1, gender:1}} ]) //OUTPUT : { “_id” : ObjectId(“5f1f23e002c633f9f578dcde”), “name” : “Aurelia Gonzales”, “isActive” : false, “gender” : “female” } db.Persons.aggregate([
MongoDB Aggregation 01 – $match $group $Sort
db.Persons.aggregate([ //stage1 {$match: {tags: {$size: 3}}} ]) db.Persons.aggregate([ //stage1 {$match: {isActive: true}} ]) db.Persons.aggregate([ //stage1 {$match: {age: {$gt: 6}}} ]) $group : Example 1 db.Persons.aggregate([