这是我的数据库
db.table_name( {
_id: “object_id()”,
user_id: <user_name>,
playlist:
{
types: "show",
video_url: “video source url”,
thumb_url: “thumb url”,
title: “video title”,
created_date: “new date()”
}
});
现在,表格指出,有一个用户,有播放列表字段,现在我希望当我第一次插入记录时,插入应该是这样的:
_id: objectid12345,
user_id: 1,
playlist:
{
types: "show",
video_url: “video source url”,
thumb_url: “thumb url”,
title: “video title”,
created_date: “new date()”
}
});
现在,当我第二次插入记录时,对于同一用户,它应该首先检查是否存在同一用户的数据?
1.如果是的话,应该像这样插入数据:
_id: objectid12345,
user_id: 1,
playlist:
{
types: "show",
video_url: “video source url”,
thumb_url: “thumb url”,
title: “video title”,
created_date: “new date()”
},
playlist:
{
types: "show",
video_url: “video source url”,
thumb_url: “thumb url”,
title: “video title”,
created_date: “new date()”
}
});
同样,当我为同一个用户进行下一次插入时,插入应该是这样的:
_id: objectid12345,
user_id: 1,
playlist:
{
types: "show",
video_url: “video source url”,
thumb_url: “thumb url”,
title: “video title”,
created_date: “new date()”
},
playlist:
{
types: "show",
video_url: “video source url”,
thumb_url: “thumb url”,
title: “video title”,
created_date: “new date()”
},
playlist:
{
types: "show",
video_url: “video source url”,
thumb_url: “thumb url”,
title: “video title”,
created_date: “new date()”
}
});
也就是说,应该为同一用户附加播放列表记录。
- 如果同一用户的记录不存在,则应在我们第一次插入记录时插入记录。
现在,我不知道如何使用猫鼬在上面的东西提前谢谢