热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

拒绝更新mongo集合中的文档子集-denyupdateonasubsetofdocumentsinamongocollection

Ihaveacollectionhookononecollectiontospawnanemptycalendar.Thisismoreorlessabase

I have a collection hook on one collection to spawn an "empty calendar". This is more or less a base that needs to be maintained unchanged, that is to say, deny updates.

我在一个集合上有一个集合钩子,以产生一个“空日历”。这或多或少是一个需要保持不变的基础,也就是说,拒绝更新。

Players.after.insert({
  // creates an empty calendar
  Calendars.insert({
    playerId: this._id
  });
});

On most calendars, update would be perfectly okay, but on these specific calendars which are inserted via this hook, I want to deny updates.

在大多数日历中,更新将完全没问题,但是在通过此挂钩插入的这些特定日历中,我想拒绝更新。

Calendars.deny({
  update: function (userId, doc) {
    // don't allow "blank" calendar to be updated
  }
});

What is the secure way to manage denying updates of a subset of documents in a collection with meteor?

使用meteor管理拒绝集合中文档子集更新的安全方法是什么?

1 个解决方案

#1


3  

To expand on my comment, seeing as nobody has answered. One way to do this is to set a flag on the 'empty' records. For instance:

扩大我的评论,看到没有人回答。一种方法是在“空”记录上设置一个标志。例如:

Players.after.insert({
  // creates an empty calendar
  Calendars.insert({
    playerId: this._id
    preventUpdate: true
  });
});

Your deny function can then be something like:

你的deny函数可以是这样的:

Calendars.deny({
  update: function (userId, doc) {
    return doc.preventUpdate === true
  }
});

This should be secure because the doc parameter in the deny function is the unmodified document from the database so couldn't be tampered with from the client.

这应该是安全的,因为deny函数中的doc参数是来自数据库的未修改文档,因此无法从客户端篡改。


推荐阅读
author-avatar
jiajiajy323
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有