package.json { “name”: “mongorelation”, “version”: “1.0.0”, “description”: “”, “main”: “index.js”, “scripts”: { “start”:”nodemon app.js” }, “author”: “”, “license”: “ISC”, “dependencies”: { “express”: “^4.17.1”, “mongoose”: “^5.10.11”,
Tag: mongoose
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 –
Working with subdocuments
The Difference between a Sub document and an Embedded Field db.books.find(“author.lastname”: “Steinbeck”) // Embedded Field I am searching for a field embedded within a sub
MongoDB and Mongoose Cheatsheet
Reference Mongoose APIs Mongoose Query APIs Cheat Sheet MongoDB $mongod : start MongoDB server (localhost:27017) $mongo : open MongoDB console (connect to local server by
Type of Schemas in MongoDB
On mongoDB using mongoose you can use two type of Schema for nested Schema. One is Embedded Schema. Another is Reference Schema. Embeded scema Embeded