【发布时间】:2017-02-01 20:56:32
【问题描述】:
我有一个收藏 - 类似于:
cmets: { 评论、所有者、匿名 }
文件可能是:
{ comment "comment1", owner: "Frazer Kirkman", anonymous: false },
{ comment "comment2", owner: "Frazer Kirkman", anonymous: true },
{ comment "comment3", owner: "HoefMeistert", anonymous: true }.
我希望始终发布评论,并且仅在匿名为 false 或用户是所有者时发布所有者。
所以上面会为弗雷泽返回这个:
{ comment "comment1", owner: "Frazer Kirkman"},
{ comment "comment2", owner: "Frazer Kirkman"},
{ comment "comment3"}.
这给霍夫:
{ comment "comment1", owner: "Frazer Kirkman"},
{ comment "comment2"},
{ comment "comment3", owner: "HoefMeistert"}.
类似:
Comments.find({},{'comment':1, 'owner':(anonymous || owner==thisUser)}}
【问题讨论】:
-
我在 MeteorJS 项目中运行这个服务器端。
-
您的架构是否看起来像这样:
{ comment "comment1", owner: "Frazer Kirkman", annonymous: false }, { comment "comment2", owner: "annonymous", annonymous: true }? -
请参阅此链接,因为我认为您可以在 mongo 中排除顶级 _id 字段。参考这个链接->docs.mongodb.com/v3.2/tutorial/…
-
嗨,谢尔盖,不,它看起来像:
{ comment "comment1", owner: "Frazer Kirkman", annonymous: false }, { comment "comment2", owner: "Frazer", annonymous: true }- 这样所有者仍然可以编辑或删除它。