Posts

Showing posts from June, 2019

Mastering in Javascript | How do JavaScript closures work?

Image
How do JavaScript closures work? When I started learning some advanced concepts of JavaScript that time I got to know about closures but when tried to understand it but it was like leave me alone. Then I did some research on it but still, I was getting only theoretical concepts of closures. So I thought might be I am not alone who don't understand closures so I tried to explain it with examples. What is Closure in JavaScript? A closure is a function having access to the parent scope, even after the parent function has closed.    A closure is one way of supporting first-class functions; it is an expression that can reference variables within its scope (when it was first declared), be assigned to a variable, be passed as an argument to a function, or be returned as a function result. this is the terminology used to explain the closure but I know how hard it is to understand, so let's go by examples. Example of Closures in JavaScript function ...

MongoDB remove unique constraint

Image
MongoDB Remove the unique constraint: Src: https://en.wikipedia.org/wiki/MongoDB Today, I'm working on a RESTful API Using Node.js With Express and Mongoose example, and I ran into a problem with the MongoDB Schema: POST : { username: 'vikaskad' , email: 'testmail@test.com' , name : 'Vikas Kad' } { [ MongoError : E11000 duplicate key error index : ecomm_database . users . $email_1 dup key : { : "testmail@test.com" }] name : 'MongoError' , err : 'E11000 duplicate key error index: ecomm_database.users.$email_1 dup key: { : "testmail@test.com " }' , and my schema is as follows: var Product = new Schema ({ username : { type : String , required : true }, email : { type : String ,unique:true, required : true }, name : { type : String }, createdAt : { type : Date , default : Date . now } }); but after some database inser...