0

I want to insert a record into my mongoDB collection, then retrieve it. Using express.js

exports.index = function(req,res){

    var MongoClient = require('mongodb').MongoClient;

    MongoClient.connect(mongourl, function(err, db) {

        var coll = db.collection('kittens');

        var obj = {
            foo: 'bar'
        };

        coll.insert(obj);

        coll.find({}, function(err, docs) {
          res.json(docs);
        });

    });

};

The server responds with 502 Proxy Error

The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request GET /urlhere/.
Reason: Error reading from remote server

If i omitt the insert(), the server will respind with an empty object.

What am i doing wrong?

Stennie
  • 63,885
  • 14
  • 149
  • 175
user2422960
  • 1,476
  • 6
  • 16
  • 28

0 Answers0