Skip to content

asaltcode/Mongodb-Product

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

MangoDb Question and Answers

  1. Find all the information about each products.

    • Solution :
       db.Product.find()
  2. Find the product price which are between 400 to 800.

    • Solution :
       db.Product.find({product_price:{$gt: 400, $lt: 800}})
  3. Find the product price which are not between 400 to 600.

    • Solution :
      db.Product.find({product_price:{$not:{$gt: 400, $lt: 600}}})
  4. List the four product which are grater than 500 in price.

    • Solution :
      db.Product.find({product_price:{$gt: 500}}).limit(4)
  5. Find the product name and product material of each products.

    • Solution :
       db.Product.find({}, {product_name: 1, product_material: 1})
  6. Find the product with a row id of 10.

    • Solution :
       db.Product.find({id:"10"}) 
                    (OR)  
       db.Product.find({id:{$eq: '10'}})
  7. Find only the product name and product material.

    • Solution :
       db.products.find({}, { "product_name": 1, "product_material": 1, "_id": 0 }) 
                                        (OR)
       db.Product.aggregate({$project:{_id:0, product_name: 1, product_material: 1}})
  8. Find all products which contain the value of soft in product material.

    • Solution :
       db.Product.find({product_material: 'Soft'})
  9. Find products which contain product color indigo and product price 492.00.

    • Solution :
       db.Product.find({$or:[{product_color: 'indigo'}, {product_price: 492}]})
  10. Delete the products which product price value are same.

    • Solution :
       db.Product.aggregate([
          {
            $group: {_id: "$product_price", count: { $sum: 1 }, ids: { $push: "$_id" }}
          },
          {
             $match: {count: { $gt: 1 }}
          },
          {
            $unwind: "$ids"
          }
        ]).forEach(function(doc){
            db.Product.deleteOne({ids: doc.ids.objectId})
        })
      

Releases

No releases published

Packages

No packages published