Angular - TypeError:path必须是$ scope.formData的字符串?

时间:2014-04-07 00:39:49

标签: javascript node.js angularjs mongodb mongoose

我有一个包含数字字段的表单:

input type="number" class="form-control" placeholder="0" ng-model="formData.position"

当我提交表单时,.error函数响应500内部服务器错误,错误:TypeError:path必须是一个字符串

$scope.createProduct = function() {

        // validate the formData (using our exentions.js .filter) to make sure that something is there
        //if form is empty, nothing will happen
        if (!isEmptyObjectFilter($scope.formData)) {

                // call the create function from our service (returns a promise object)
                Emotions.create($scope.formData)

                        // if successful creation, call our get function to get all the new emotions
                        .success(function(data) {
                                $scope.formData = {}; // clear the form so our user is ready to enter another
                                $scope.products = data; // assign our new list of emotions
                        })
                        .error(function(data) {
                                console.log('Error: ' + data);
                        });
        }
};

formData可以是字符串和整数的混合吗?

这是服务中的创建行:

    create : function(emotionData) {
        return $http.post('/api/emotions', emotionData);
    },

我有一个Mongoose架构,如下所示:

var ProductSchema = mongoose.Schema({
    title : String,
    position: Number
});

错误的堆栈跟踪如下所示:

TypeError: path must be a string
    at Query.where (/Users/KK/Downloads/awaken/v16/node_modules/mongoose/lib/query.js:593:11)
    at Function.where (/Users/KK/Downloads/awaken/v16/node_modules/mongoose/lib/model.js:1040:18)
    at model.<anonymous> (/Users/KK/Downloads/awaken/v16/app/models/emotion.js:44:35)
...

这看起来会导致emotion.js文件的这一行(44?):

mongoose.model("Product").where({_id: {$ne: doc._id}, position: doc.position}).count( function (err, count) {

这就是我在这里发布的内容:

Increment field on all records in Mongo?

0 个答案:

没有答案