Meteor Methods 不使用 Autoform 更新数据库

Meteor Methods doesn't update database using Autoform

使用 autoform,似乎数据是从 autoform 传递的,因为我服务器上的 Meteor 方法确实获取了数据,但是随后在我的方法中进行数据库更新并没有更新我的数据库...这是怎么回事我不见了?

自动格式代码...

{{> quickForm collection="Rooms" type="method-update" 
      doc=this autosave=true id=makeUniqueID 
meteormethod="updateRoom"}}

流星法:

updateRoom: function (room) {
  console.log(room);
  Rooms.update({_id: room._id}, { $set: {
    checkIn: room.checkIn,
    checkOut: room.checkOut,
    tenantID: room.tenantID,
    available: room.available,
    needCleaning: room.needCleaning,
}});
},

我的 allow/deny 规则:

Rooms.allow({
 insert() { return false; },
 update() { return false; },
 remove() { return false; }
});

Rooms.deny({
 insert() { return true; },
 update() { return true; },
 remove() { return true; }
});

下面是我从我的 meteor 方法的控制台日志中得到的。所以我确实得到了更改(在这种情况下将 tenantID 和 false 更改为可用),但它不会在数据库中更新。我在某处遗漏了一些细节,但此时看不到。

您传递给方法的 room 变量将所有内容嵌套在 modifier$set: 键下。

你可以简单地做:

updateRoom: function (room) {
  Rooms.update({_id: room._id}, room.modifier);
},

但这真的很不安全,因为你将整个修饰符传递给方法,而黑客可以传递他们想要的任何东西。

更好:

updateRoom(room) {
  check(room,Object);
  check(room._id,String);
  {checkIn, checkOut, tenantId, available, needCleaning } = room.modifier.$set;
  Rooms.update(room._id, { $set: {checkIn, checkOut, tenantId, available, needCleaning }}); 
},