1

I have the following schema:

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

How can I add projectId by using http.put?

This is among the things that I have tried:

$http.put('/api/users/'+User._id, {'projects': project._id});
4
  • you want to have projects': project._id in UserSchema object? Commented Jun 4, 2015 at 2:29
  • Does your API controller support this action? Are you in control of the REST Service?From what I see you are using Microsoft WebApi. If that is the case you need to code your controller to do this or, look into using the ODATA controller instead. Commented Jun 4, 2015 at 4:01
  • I am creating a many-to-many relation between Users and Projects. Thought this was the way to do it? I am using the angular fullstack generator. In other words; yes, I am in control of the REST Service, and it is not a Microsoft WebApi. Commented Jun 4, 2015 at 9:16
  • I have it the same way in ProjectSchema (array of user id's). Commented Jun 4, 2015 at 9:26

1 Answer 1

5

Solved it using:

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

and in my update method:

_.extend(user, req.body);

instead of

_.merge(user, req.body);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.