My Schema looks like:
var FriendSchema = new Schema({
friend_id: String,
gender: String,
meta: {
address: String,
amount: Number
}
}, { _id : false });
var GroupSchema = new Schema({
unique_id: {
type: Number,
required: true,
unique: true
},
friends: [FriendSchema]
});
So a Group contains an array of friends and a friend has a meta with some information in it. I want to update a specific friend in the group that matches certain criteria. Here's what I've tried:
groupQuery = {unique_id: someId, 'friends.friend_id': friendNum, 'friends.gender': gender}
groupUpdate = {$set: {'friends.$.meta.address': myAddress, 'friends.$.meta.amount': debt}}
Group.update groupQuery, groupUpdate, (err) ->
What happens is the last friend in the group gets updated. Not the specific one that I want. What am I doing wrong?
GroupSchemausesfriendsand your code usesfriend.friendsgets updated, then that element must match your query.