简体   繁体   中英

how can i change string format of Price in database to integer format in mongodb?

This is my input form. Here, the Price label save as string in Database . How can change it into integer format. I'm using mongodb 3.2 version

  <section>
    <div class="container mt-4">
    <div class="row">

        <div class="col-md-6">
            <h2 class="text-center">Add Product</h2>
            <form action="/admin/add-product" method="POST" enctype="multipart/form-data">
                <label for="">Name</label>
                <input type="text" name="Name" class="form-control">

                <label for="">Category</label>
                <input type="text" name="Category" class="form-control">

                <label for="">Price</label>
                <input type="number" name="Price" class="form-control">

                <label for="">Description</label>
                <input type="text" name="Description" class="form-control">

                <label for="">Image</label>
                <input type="file" name="Image" class="form-control">

                <button type="submit" class="btn btn-success mt-4">Submit</button>
            </form>
        </div>

    </div>
    </div>
</section>

Add to cart

    addProduct:(product,callback)=>{


    db.get().collection("product").insertOne(product).then((data)=>{
        console.log(data)
        
        callback(data.ops[0]._id)
    })
    

}

Before adding the product to database change Price to integer

     let Price=parseInt(req.body.Price)
      req.body.Price=Price

then add product to mongodb

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM