2016-04-23 68 views
0

我試圖從AngularJS形式做Couchbase一個簡單的CRUD操作,但我不斷收到此錯誤:Couchbase插入 - 類型錯誤:轉換圓形結構,以JSON

TypeError: Converting circular structure to JSON 

以下是主要的片段AngularJS和Express.js。任何幫助將不勝感激。

//AngularJS 
$http.post('docs', $scope.doc).then(function(res) { 
    console.log(res); 
}, function(err) { 
    console.log(err); 
}); 

//Express.js 
router.post('', function(req, res, next) { 

    db.upsert('anyname', req.body, function(error, result) { 
     if (error) { 
     console.log('operation failed', error); 
     return; 
     } 

     res.send(res); 
    }); 

}); 

從終端詳細的出錯:

/Users/name/Workspace/sb-couchbase/node_modules/express/lib/response.js:242 
    var body = JSON.stringify(val, replacer, spaces); 
       ^

TypeError: Converting circular structure to JSON 
    at Object.stringify (native) 
    at ServerResponse.json (/Users/name/Workspace/sb-couchbase/node_modules/express/lib/response.js:242:19) 
    at ServerResponse.send (/Users/name/Workspace/sb-couchbase/node_modules/express/lib/response.js:151:21) 
    at /Users/name/Workspace/sb-couchbase/routes/document.js:36:8 

回答

0

問題是一個簡單的Express.js錯誤。終點的res.send(res)應該是res.send(result)。這解決了問題。

所以:

//Express.js 
router.post('', function(req, res, next) { 

    db.upsert('anyname', req.body, function(error, result) { 
     if (error) { 
     res.send(error); 
     return; 
     } 

     res.send(result); 
    }); 

}); 
相關問題