Posts

Showing posts with the label mongodb

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 find the data by its id in the mongodb in express.js // findById() query

  Userimages . findById ({ _id : newid ,}, function ( err , gall ){       if ( err ){           console . log ( err )       }         else {              // do this                      } })

How to find the one data from the multiple data from the mongodb in express js // findOne() query

  const newid = req . params . shopid     Userid . findOne ({ _id : newid }, function ( err , item ){         if ( err ){             console . log ( err )         }           else {              // do this                   }     }

how to find or search the data in the mongodb using in express.js / find query

  app . get ( '/searchshop' , function ( req , res ){     const item = req . query . find     Userid . find ({ shopname : item }, function ( err , shops ){         if ( err ){             console . log ( err )         }           else {              //do this           }     } }

How to create a data or insert a data into the mongodb in express.js

  app . post ( '/signup' , function ( req , res ){     const signupdata = req . body     Userid . create ( signupdata , function ( err , result ){         if ( err ){             console . log ( err )         }         else {            //do something         }     }) })

How to design the Schema of monggoose in the node js/express js

  const productSchema = new mongoose . Schema ({     _id : ObjectId ,     catagarie : [{         catagariename : { type : String },         products : [{             productname : { type : String },             productprice : { type : String },         }],     }] }) const Products = mongoose . model ( 'product' , productSchema ); const PPSchema = new mongoose . Schema ({     // name : {type:String,required:true},     name : { type : String },     shopname : { type : String },     phonenumber : { type : String },     secondarynumber : { type : String },     email : { type : String },     dealer : { type : String },     about : [{         data : { type : String },         disc : { type : String } ...

How to use mongodb in node js /expressjs

const mongoose = require ( 'mongoose' ) mongoose . connect ( "mongodb://127.0.0.1:27017/PP" , { useNewUrlParser : true , useUnifiedTopology : true }) //127.0.0.1:27017/? const db = mongoose . connection db . once ( 'open' , function () {     console . log ( 'we are connected ' ) });