我有一个用户模型,其中包含对其他用户的引用数组:
friends : [ { type: Schema.Types.ObjectId, ref: 'User' } ]
我该怎么从这个列表中删除一个项目?下面是我目前尝试的方法:
var index = user.friends.indexOf(friend_id);
这样可以正确获取该项的索引。现在我要尝试进行splice操作:
user.friends = user.friends.splice(index, 1);
user.save();
很不幸,这个没有起作用。有什么建议吗?