Tuesday 30 May 2017

Search for all values in Mongo DB

I am trying to make a reservation mongoose schema for restaurant but i don't want to people be able to place a reservation if people value is more than 50 in all collections.

var reservationSchema = new mongoose.Schema ({
    people: Number,
    date: String,
    name: String,
    email: String
});

var Reservation = mongoose.model("Reservation", reservationSchema);

app.post('/reservation', (req, res) => {
    var people = parseFloat(req.body.people);
    var date = req.body.date;
    var name = req.body.name;
    var email = req.body.email;   

    var newReservation = {people: people, date: date, name: name, email: email};
    Reservation.create(newReservation, (err, newlyCreated) => {
        if(err) {
            console.log(err);
        } 
        else {
            res.redirect('/');
        }
    })
});

Is there any way to filter through all collection to find what is the number when you add up all the values from people?



via JKshort

No comments:

Post a Comment