我有一个收藏,最初我们拥有以下结构的评论文档。
现在,当管理员审核此文件时,会添加一个状态字段来更新该文件为:
由于某些原因,我最初无法拥有状态,必须在管理员审核后将其放入,并附带批准或不批准的值。
因此,现在获取所有由用户创建并已批准的评论的查询将类似于.... db.reviews.find({"crBy":ObjectId(...),"status":"approved"})
我通过创建一个包含crBy和status字段的索引来优化读取 我的问题是:
提前感谢。
{
_id:ObjectId(...),
comment:"hi, test comment",
crBy:ObjectId(...)
}
现在,当管理员审核此文件时,会添加一个状态字段来更新该文件为:
{
_id:ObjectId(...),
comment:"hi, test comment",
crBy:ObjectId(...),
status:"approved"
}
由于某些原因,我最初无法拥有状态,必须在管理员审核后将其放入,并附带批准或不批准的值。
因此,现在获取所有由用户创建并已批准的评论的查询将类似于.... db.reviews.find({"crBy":ObjectId(...),"status":"approved"})
我通过创建一个包含crBy和status字段的索引来优化读取 我的问题是:
1.Am i creating the index in the right way?
2. I have read that indexes should contain fields that don't change. So in my case status field gets inserted afterwards. How does it
impact my performance?
3. Considering my case, what do you suggest to be the best possible way to optimize reads in such a scenario where a field comes later
on?
提前感谢。