【发布时间】:2013-09-15 04:27:42
【问题描述】:
这是我的数据库
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()”
}
});
也就是说,应该为同一用户附加播放列表记录。
- 如果同一用户不存在记录,则应在我们第一次插入记录时插入记录。
现在,我不知道如何使用 mongoose 提前致谢
【问题讨论】:
标签: node.js mongodb express mongoose nosql