I'm trying to combine the 2 objects and save them to the collection. But as I'm really new to Node.js/Express I think I'm missing something. All advice is welcome!
Thx in advance for your precious time.
This is what I puzzled together but doesn't work:
app.post('/:collection', function(req, res) {
    var object = req.body;
    var collection = req.params.collection;
    geocoder.geocode(req.body.address.street + req.body.address.no + req.body.address.zip + req.body.address.city, function(req, res) {
    var gpslocation = ({"loc": [res[0].longitude, res[0].latitude]});
    mergedObject = JSON.parse((JSON.stringify(object) + JSON.stringify(gpslocation)).replace(/}{/g,","))
    console.log(mergedObject);
    });
    collectionDriver.save(collection, object, function(error,docs) {
          if (error) { res.send(400, error); }
          else { res.send(201, docs);} //B
   });
});
output(console.log) but actual save is working but not with the longitude/latitude appended to it:
{ cat: 'Electrician6',
name: { first: 'John', last: 'Pipe', picture_ID: '23872' },
created_at: '2015-05-16T14:05:23.431Z',
_id: '55574ea3435c2d9c24d21572',
loc: [ 4.7261822, 50.9635574 ] }
But when I edit it to:
app.post('/:collection', function(req, res) { //A
    var object = req.body;
    var collection = req.params.collection;
    geocoder.geocode(req.body.address.street + req.body.address.no + req.body.address.zip + req.body.address.city, function(req, res) {
    var gpslocation = ({"loc": [res[0].longitude, res[0].latitude]});
    mergedObject = JSON.parse((JSON.stringify(object) + JSON.stringify(gpslocation)).replace(/}{/g,","))
    console.log(mergedObject);
    });
    collectionDriver.save(collection, mergedObject, function(error,docs) {
          if (error) { res.send(400, error); }
          else { res.send(201, docs);} //B
   });
});
output:
ReferenceError: mergedObject is not defined
    at app.put.params (/app/testapp/index.js:92:39)
    at callbacks (/app/testapp/node_modules/express/lib/router/index.js:161:37)
    at param (/app/testapp/node_modules/express/lib/router/index.js:135:11)
    at param (/app/testapp/node_modules/express/lib/router/index.js:132:11)
    at pass (/app/testapp/node_modules/express/lib/router/index.js:142:5)
    at Router._dispatch (/app/testapp/node_modules/express/lib/router/index.js:170:5)
    at Object.router (/app/testapp/node_modules/express/lib/router/index.js:33:10)
    at next (/app/testapp/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at Object.staticMiddleware [as handle] (/app/testapp/node_modules/express/node_modules/connect/lib/middleware/static.js:55:61)
    at next (/app/testapp/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    { cat: 'Electrician6',
    name: { first: 'John', last: 'Pipe', picture_ID: '23872' },
    loc: [ 4.7261822, 50.9635574 ] }
 
     
    