0
const mongoose = require("mongoose");

const bills = new mongoose.Schema({
  companyId: mongoose.Schema.Types.ObjectId,
  billNo: Number,
  partyName: String,
  billedProduct: [{
    productName: String,
    price: Number,
    quantity: Number
  }],
  billDate: {
    type: Date,
  },
});


module.exports = mongoose.model("Bills", bills);

    export function addBill(req, res) {
  const { partyName, product, price, quantity } = req.body;

  var billObj = {
    companyId: req.user._id,
    billedProduct: [{
      product,
      price,
      quantity,
    }],
    partyName,
    billDate: Date.now(),
  };
  var newBill = new Bills(billObj);
  newBill
    .save()
    .then(bill => {
      console.log(bill);
      return res.json(bill);
    })
    .catch(err => {
      return res.json(err);
    });
}

So following is the schema i want billNo to be increment by 1 on every new bill is saved ?

Now in addBill function on time of saving or creating new bill i want to billNo to be increment by 1 on every new bill created

Huzaifa Ahmed
  • 304
  • 1
  • 3
  • 15
  • This is not solving my problem i had already tried that – Huzaifa Ahmed Nov 17 '18 at 16:03
  • Don't see anything "trying that" in the question you actually asked. There's also more than one answer, and more than one statement as to why this is probably a bad idea anyway. – Neil Lunn Nov 18 '18 at 21:57

0 Answers0