Posts

Showing posts with the label nodejs

how to apply two conditions on fetching the data from single array in mongodb in express

  User . findOne ({ 'About.Phone' : phone , 'About.Password' : password }, function ( err , result ){         if ( err ){             console . log ( err )         }         else {                   }     }) // about is the name of array and phone,password is the sub part of the object

how to fetch the data from the mongodb with the help of data inside the array // or nested array

  const PPSchema = new mongoose . Schema ({     product : [{         catagariename : { type : String },         products : [{             productname : { type : String },             productprice : { type : String },         }],     }] })           Userid . find ({ 'product.catagariename' : pdt }, function ( err , result ){                 if ( err ){                     console . log ( err )                                     }                 else {                                     }    ...

how to insert the values in the array

  const UserSchema = new mongoose . Schema ({         About : [{             FullName : { type : String },             UserName : { type : String },             Phone : { type : String },             DOB : { type : String },             Email : { type : String },             Password : { type : String }         }],         Earnings : { type : String },         Settings : { type : String }     });      const user_ids = {         About : [ req . body ] // inserting the only aboute values of the user     }     User . create ( user_ids , function ( err , result ){         if ( err ){             conso...

how to update the value in the array of array in mongodb using express

const productSchema = new mongoose . Schema ({     _id : ObjectId ,     catagarie : [{         catagariename : { type : String },         products : [{             productname : { type : String },             productprice : { type : String },         }],     }] }) Products . updateOne ({ _id:newid , 'catagarie.catagariename' :prdid }, { '$push' : { 'catagarie.$.products' :updatedata }}, function ( err , result ){         if ( err ){             console . log ( err )         }             })

how to move one page back in the express or how to redirect a page to the back page in the express

  app . post ( '/signup' , function ( req , res ){         console . log ( req . body )     res . redirect ( 'back' ) })

how to build a sever from node js

  const http = require ( 'http' ) const fs = require ( 'fs' ) http . createServer ( function ( req , res ){     // res.writeHead(200,{'content-Type':'text/html'})     // res.end('hello world')     // res.end('the server is working ')     fs . readFile ( 'tut_1.html' , function ( err , data ){         if ( err ){             console . log ( err )             // res.writeHead(200,{'content-Type':'text/html'})         }         res . writeHead ( 200 ,{ 'content-Type' : 'text/html' })         res . write ( 'data' )     })     // res.write(data)     }). listen ( 80 , function (){     console . log ( 'connected' ) })