How To Concatenate MongoDB Queries

I am using the find() in mongodb with mongoskin

I am trying to grab two collections.

/* GET drawingList */
router.get('/drawinglist', function(req, res) {
    var db = req.db;
    db.collection('drawingList').find().toArray(function (err, items) {
        res.json(items);
    });
});

// GET drawingQty
router.get('/drawinglist', function(req, res) {
    var db = req.db;
    db.collection('drawingQty').find().toArray(function (err, items) {
        res.json(items);
    });
});

I try and merge them together like this,

router.get('/drawinglist', function(req, res) {
    var db = req.db;
        db.collection('drawingList').find().toArray(function (err, items) 
            db.collection('drawingQty').find().toArray(function (err, items)  {
                res.json(items);
    });
});

But the program wont run. What is the correct way to concatenate this?

This is more a JavaScript problem than a mongoDB one. In your example only the result of the second query will be returned, because you use the same items variable within the two callbacks. The second will overwrite the first.

This should give you a hint, what to do:

router.get( '/drawinglist', function( req, res ) {
    var db = req.db;
    db.collection( 'drawingList' ).find().toArray( function( err, items ) {
        db.collection( 'drawingQty' ).find().toArray( function( err, items2 )  {
            var items3 = items.concat( items2 ); // or however you want to "merge"
            res.json( items3 );
        });
    });
});