Node.js Mongoose-为值\“转换为ObjectId失败;[对象对象]\";在路径\";responsavel\";

Node.js Mongoose-为值\“转换为ObjectId失败;[对象对象]\";在路径\";responsavel\";,node.js,mongodb,mongoose,restangular,Node.js,Mongodb,Mongoose,Restangular,我是一个新手,在过去的三天里一直在学习 当我尝试保存具有一对五关系的新对象时,会出现此错误。我正在使用restanglar+mongoose,无法找到错误的来源 以下是我在提交表单时进行的保存: $scope.saveProjeto = function() { console.log($scope.projeto); Projeto.post($scope.projeto).then(function() { $location.path('/projetos'); });

我是一个新手,在过去的三天里一直在学习

当我尝试保存具有一对五关系的新对象时,会出现此错误。我正在使用restanglar+mongoose,无法找到错误的来源

以下是我在提交表单时进行的保存:

$scope.saveProjeto = function() {
  console.log($scope.projeto);
  Projeto.post($scope.projeto).then(function() {
    $location.path('/projetos');
  });
};
以下是我的用户模型:

var mongoose = require('mongoose')
Schema = mongoose.Schema,
relationship = require('mongoose-relationship');

// Creating Schema
var UserSchema = Schema({
  nome: {
    type: String,
    required: true
  },
  sobrenome: {
    type: String,
    required: false
  },
  email: {
    type: String,
    required: true
  },
  password: {
    type: String,
    required: true
  },
  projetos: [{
    type: Schema.ObjectId, ref: "Projeto"
  }]
});

// Exporting Model Schema
module.exports = UserSchema;
这是我的项目模型:

var mongoose = require('mongoose'),
Schema = mongoose.Schema,
relationship = require('mongoose-relationship');

// Creating Schema
var ProjetoSchema = Schema({
  nome: {
    type: String,
    required: true
  },
  responsavel: {
    type: Schema.ObjectId,
    ref: "User",
    required: true
  },
  descricao: {
    type: String
  },
  data_inicio: {
    type: Date,
    required: true
  },
  data_fim_prevista: {
    type: Date,
  },
  data_fim: {
    type: Date,
  },
  created_at: {
    type: Date,
    required: true
  },
  updated_at: {
    type: Date,
    required: true
  }
});
这是我在控制台上看到的:

message: "Cast to ObjectId failed for value "[object Object]" at path 

"responsavel""
name: "CastError"
path: "responsavel"
type: "ObjectId"
value: {_id: "5553afb5d65550216c26d69f", nome: "Renato", sobrenome: "Correa", email: "renatojf2@gmail.com",…}
__v: 0
_id: "5553afb5d65550216c26d69f"
email: "foobar@gmail.com"
fromServer: true
nome: "Renato"
parentResource: null
password: "foobar"
projetos: []
reqParams: null
restangularCollection: false
restangularized: true
route: "users"
sobrenome: ""

尝试将响应文件中的ref:'User'更改为ref:'UserSchema'尝试将
类型:Schema.ObjectId
更改为
类型:Schema.Types.ObjectId
。对于
responseAvel
字段。尝试了两个选项,但没有任何区别。。相同错误:(您的用户正在导出模式,而不是模型(例如:
mongoose.model('user',UserSchema)
)。这可能是个错误。我也不确定您是在创建Projeto模型,还是在使用
mongoose关系
。如果是这样,您可以发布完整的模型文件吗?很抱歉,响应太晚。.我正在忙其他事情。.我正在使用mongoose关系。.这些是我的完整模型文件。