【问题标题】:Best way to exclude a Meteor value from the database?从数据库中排除 Meteor 值的最佳方法?
【发布时间】:2015-08-20 13:26:04
【问题描述】:

在使用 Autoform、SimpleSchema、Collection2 等时,从 Meteor 中的数据中排除字段值的最佳方法是什么?说我有:

MySchema = new SimpleSchema({
  password: {
    type: String,
    label: "Enter a password",
    min: 8
  },
  confirmPassword: {
    type: String,
    label: "Enter the password again",
    min: 8,
    custom: function () {
      if (this.value !== this.field('password').value) {
        return "passwordMismatch";
      }
    }
  }
});

...而且我不想将 ConfirmPassword 字段持久化到数据库中,最好的处理方法是什么?我假设使用钩子,但如果是这样,在哪里以及如何?希望有一种方法可以只排除一个(或多个)值,而不必重新定义整个模式来说明要包含哪些以及要排除哪些。如果我有 100 个字段并且想要排除 1,希望钩子或其他不需要其他 99 的东西也被玷污。

TIA

【问题讨论】:

    标签: meteor meteor-autoform meteor-collection2


    【解决方案1】:

    使用 autoform,您必须在服务器端使用方法。在插入文档之前,只需在服务器收到方法代码中删除该字段即可。

    【讨论】:

    • 类似 myMehtod(doc)... doc.delete(extrastuff)...collection.insert(doc)?如果可行,会试一试并标记答案 - 谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-12
    • 2011-02-24
    • 1970-01-01
    • 2016-05-22
    相关资源
    最近更新 更多