我主要通过搜索各种Mongoose的代码例子来学习,但对于嵌套数组的排序和筛选操作搜不到,特来请教。
Article = new Schema({
//blablabla 其它数据
comments: [{content: String, time: {type: Number, default: Date.now}}],//直接就是数组数据,没有为comment建一个Schema,有必要建一个吗?
}, {strict: true});
comments的time的数据类型是13位时间戳数字 想对comments数组进行time排序(正序或倒序),以及按time所处于的日子显示(例如 time处于 今天的凌晨和23:59:59之间就视为是今天的评论)。
如果在用mysql,我会为comments建一个表,每条comment都有文章id,这种关系在MongoDB上该怎么样转变和实现呢?