Monday 29 May 2017

Mongodb query results not displayed on webpage

We have created a webpage using jade, and node.js. We are able to insert data from the webpage to a collection in MongoDB, but the query results are not displayed on the webpage. Here is a snippet of our code:

router.get('/query', function(req, res, next) {
res.render('query', { title: 'Get Molecules' });});

router.post('/query',function(req,res,next){
    var db = req.db;
    var collection1 = db.get('MCdata');
    var varMC = req.body.mc;
    var vargrp1 = req.body.grp1;
    var vargrp2 = req.body.grp2;
    var varpos1 = req.body.pos1;
    var varpos2 = req.body.pos2;

collection1.find
({"MC":varMC,"Group1":vargrp1,"Group2":vargrp2,"Position1":varpos1,"Position2":varpos2},function(err, doc) {
    if(err)         res.json(err);
    else{
            res.send(doc);
    }
});
});

Also, the type set for all the variables is "number", in the jade file.

Here is the snippet of the jade file: extends layout block content

    center

            <strong><h1 style="font-family: courier; 
color:#342D7E">Molecular Structures </h1></strong>

            style.

                    body{background:MediumAquaMarine}

    form(name="query", method="post")

            div.input

                    center

                            <h2 style="font-family:verdana;">MC:</h2>

                            input(type="number", name="mc", max="18", 
min="1"  required)

            div.input

                    center

                            <h2 style="font-family:verdana;">Position1:
</h2>

                            input(type="number", name="pos1", required)

            div.input

                    center

                            <h2 style="font-family:verdana;">Group1:
</h2>

                            input(type="number", name="grp1", required)

            div.input

                    center

                            <h2 style="font-family:verdana;">Position2:
</h2>

                            input(type="number", name="pos2", required)

            div.input

                    center

                            <h2 style="font-family:verdana;">Group2:
</h2>

                            input(type="number", name="grp2", required)



via 204

No comments:

Post a Comment