0
我正在使用像follow模型一样的twitter,为此我的用户模式如下。使用Node.js更新MongoDB中的文档集合
var UserSchema = new Schema({
username: {type: String, match: /^[a-zA-Z0-9_]+$/, unique: true},
email: { type: String, unique: true },
password: String,
followings : [{ type: ObjectId, ref: 'User' }],
followers : [{ type: ObjectId, ref: 'User' }] });
我需要在下面和追随者字段中存储用户的ObjectId。
我不知道如何插入和更新以下和追随者集合。 我尝试使用“更新”,但每次都会覆盖。 然后尝试推,但没有帮助。
请帮帮我。
在此先感谢。
如何从集合中删除特定文档? –
尝试命令$ pullAll。从阵列中删除所有对象。检查手册。 – golja