I'm having some trouble updating my mongoDB from a Node server. Sorry, but I'm having some trouble tagging the code. Might come out as regular text. The error i get is on the node server and states as follows:

Cast to string failed for value "undefined" at path "text"

Here's my code:

web-server:

app.post('/updateArticle/', function(req, res){
console.log("Updating article");
articleModel.update(
    {id: req.id},
    {$set: {title: req.title, text: req.text}});

"services:

wikiServices.factory('articleService', function($http, $routeParams){
return{
    getArticles: function(callback){
        $http.get('articles/' + $routeParams.article).success(callback);
    },
    updateArticle: function(article, callback){
        $http.post('updateArticle/', article);
    }
};

controllers:

wikiControllers.controller('articleController', ['$scope', 'articleService',         '$routeParams', '$sanitize',
function($scope, articleService, $routeParams, $sanitize){
articleService.getArticles(function(result){
  $scope.article = result[0];
  console.log($sanitize(result[0].text));
  $scope.articleHTML = $sanitize(result[0].text);
});
$scope.update = function(article, callback){
  articleService.updateArticle(article);
  console.log("test");
};

articleEdit:

<div text-angular="text-angular" ng-model="article.text"></div>
<div ng-bind-html="article.text"></div>
<a href="#/articles/{{article.id}}">Tilbake</a>
<button ng-click="update()">Lagre forandringer</button> 
share
    
You have missed some important details. Are you receiving data on the server, or updated data is not being send from client? You need to narrow down whether the error is on server or client or a communication issue. – Chandermani Jan 15 '14 at 12:50
    
The error message I get is: Cast to string failed for value 'undefined' at path 'text', as a server error. – Torby Jan 15 '14 at 12:51
2  
Replace your console.log above with console.log("Updating article", req) to see if your request actually contains the post fields you think – Anders Bornholm Jan 15 '14 at 13:00
    
Tried: console.log("Updating article", req.article); Got 'undefined'. If I just typed console.log("Updating article", req); I got a really long text which the server log couldn't handle. – Torby Jan 15 '14 at 13:04
    
Nvm, guys. Found the answer... thanks for your help :) – Torby Jan 15 '14 at 14:22
up vote 0 down vote accepted

I forgot to send the object in the HTML-function. update("article.text");

share

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.