如何在angularjs中的http.put中将元素推送到数组?

mrl*_*sen 1 api mongoose mongodb angularjs

我有以下架构:

var UserSchema = new Schema({
  name: String,
  email: { type: String, lowercase: true },
  projects: [{type: Schema.ObjectId, ref:'Project'}],
  //....
}
Run Code Online (Sandbox Code Playgroud)

如何projectId使用添加http.put

这是我尝试过的事情之一:

$http.put('/api/users/'+User._id, {'projects': project._id});
Run Code Online (Sandbox Code Playgroud)

mrl*_*sen 5

解决它使用:

$http.put('/api/users/'+User._id, {'projects': User.projects});

在我的更新方法中:

_.extend(user, req.body);

代替

_.merge(user, req.body);