These are chat archives for Automattic/mongoose

Sep 2017
Abdul-Samii Ajala Olalekan
Sep 06 2017 11:22

I am using ordinary node with mongoose to build an api server. when I try this:

const Router = (req, res) => {
  res.setHeader("Access-Control-Allow-Origin", "*");
  res.setHeader("Access-Control-Allow-Methods", "GET, POST");
  res.writeHead(200, {"Content-Type": "text/json"});

  let path = url.parse(req.url).pathname;
  let modules = path.split("/");

  var test = {
    warning: "this is just a test data!, Request from the specified endpoints!!!",
    type: 'response',
    just: "testing",
    inner: {
      "hu": 'hey',
      hi: "there!"
    tfare: 30

  switch (path) {
    case '/':
      res.write(JSON.stringify(test, undefined, 2));
    case '/users/total':
      Users.count({}, (err, total) => {
        if(!err) {
          console.log("total no. of users: ", total);
        } else {
          console.log('error', err);

const server = http.createServer(Router);

path '/' works fine, serving the test data but path 'users/total/' gives this error =>

      throw er; // Unhandled 'error' event

TypeError: Cannot read property 'Symbol(asyncId)' of null
    at write_ (_http_outgoing.js:636:24)
    at ServerResponse.write (_http_outgoing.js:630:10)
    at Router.Users.count (/Users/jalasem/workspace/swipe/737/index.js:56:15)
    at model.Query.<anonymous> (/Users/jalasem/workspace/swipe/737/node_modules/mongoose/lib/model.js:3832:16)
    at /Users/jalasem/workspace/swipe/737/node_modules/kareem/index.js:273:21
    at /Users/jalasem/workspace/swipe/737/node_modules/kareem/index.js:131:16
    at _combinedTickCallback (internal/process/next_tick.js:95:7)
    at process._tickCallback (internal/process/next_tick.js:161:9)
Mårten Pettersson
Sep 06 2017 15:44
Hi guys. What's the best way to do soft removes in mongoose?