Javascript Mongo中所有记录的增量字段?

Javascript Mongo中所有记录的增量字段?,javascript,node.js,angularjs,mongodb,mongoose,Javascript,Node.js,Angularjs,Mongodb,Mongoose,该错误实际上是在angular ItemController中抛出的,error:TypeError:path必须是字符串 如果由于在新位置与现有位置匹配时向下移动每条记录而导致500个内部服务器错误,则添加此项 } else if(typeof doc.position == "number") { console.log('yes, a number'); // check if there is an existing document with the same p

该错误实际上是在angular ItemController中抛出的,error:TypeError:path必须是字符串

如果由于在新位置与现有位置匹配时向下移动每条记录而导致500个内部服务器错误,则添加此项

 } else if(typeof doc.position == "number") {

    console.log('yes, a number');

    // check if there is an existing document with the same position
    // use mongoose.model to fetch the model because the model is not compiled yet
    mongoose.model("Product").where({_id: {$ne: doc._id}, position: doc.position}).count( function (err, count) {

        // if there was an error, pass it to next()
        if(err)
            return next(err);

        // if there is a doc with the same position, execute an update to move down all the $gte docs
        if(count > 0) {
            // use mongoose.model to fetch the model because the model is not compiled yet
            mongoose.model("Product").update({position: {$gte: doc.position}}, {position: {$inc: 1}}, {multi: 1}, function(err, numAffected) {

                console.log(numAffected);

                // Call next() (with or without an error)
                next(err);
            });

        } else {
            //  there are no docs that need to move down, so call next()
            next();
        }
    });
我在Mongoose文档上有一个“位置”字段,用于通过前端角度循环对结果进行排序

var ProductSchema = mongoose.Schema({
    title : String,
    position: Number
});
对于未输入“position”的新文档,架构从“if”语句自动递增

// before validation starts, the number of Products is counted
// afterwards, the position is set
ProductSchema.pre("validate", function(next) {

    var doc = this;

    // if 'position' is not filled in, fill it in
    // not using !position because 0 might be a valid value
    if(typeof doc.position !== "number") {
        // count the number of Products *
        // use mongoose.model to fetch the model..because it's not compiled yet
        mongoose.model("Product").count(function(err, num) {
            // if there was an error, pass it to next()
            if(err)
                return next(err);

            // set the position, then call next();
            doc.position = num;
            return next();
        });
..并且由于'else'语句,对于带有手动输入的表单字段'position'的新文档,架构以其他方式正确存储文档

    } else {
        //  there is no need to count or update positions, so call next()
        next();
    }
});

module.exports = mongoose.model('Product', ProductSchema);
前端:输入类型=数字类=表单控件占位符=0 ng模型=formData.position


错误来自哪一行?@AaronDufour发现错误实际上是在angular ItemController中抛出的,错误:TypeError:path必须是刚刚添加ItemController代码的字符串。。有什么建议吗?
    } else {
        //  there is no need to count or update positions, so call next()
        next();
    }
});

module.exports = mongoose.model('Product', ProductSchema);