You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何阻止Parse-Server自动新增对象字段至Parse仪表盘?

How to Prevent Parse from Automatically Creating New Columns in the Dashboard

Sure thing! You can absolutely stop Parse from automatically creating new columns in your dashboard when you save objects with unrecognized fields. Let’s break down the different ways to do this, depending on your setup:

1. Restrict Field Creation with Class Level Permissions (CLPs)

This is the simplest approach if you’re using the managed Parse Platform or a self-hosted dashboard:

  • Open your Parse Dashboard and navigate to the target class (like your "Media" class).
  • Go to the Security tab, then select Class Level Permissions.
  • Find the "Add Field" permission and remove it from all roles (including public, if you don’t want any client-side code adding fields).
  • Now, any attempt to save an object with a new field will throw on} c� icon Type Angelaw proceeds al, it will throw an error instead of creating a new column in the dashboard.
  • Pro tip: If your server-side code (like Cloud Code) needs to add fields intentionally, create a dedicated role with "Add Field" access and assign it to your server logic.

2. Enforce Field Validation with Cloud Code

For granular control over exactly which fields are allowed, use a beforeSave trigger to block invalid fields before they’re saved:

  • Add this snippet to your Cloud Code:
    Parse.Cloud.beforeSave("Media", async (request) => {
      // List all fields you explicitly allow for this class
      const allowedFields = ["existingField1", "existingField2", "foo"];
      const objectFields = Object.keys(request.object.toJSON());
      
      // Check for any fields not in the allowed list
      const invalidFields = objectFields.filter(field => !allowedFields.includes(field));
      if (invalidFields.length > 0) {
        throw new Parse.Error(
          Parse.Error.INVALID_KEY_NAME,
          `Invalid fields detected: ${invalidFields.join(", ")}. Only ${allowedFields.join(", ")} are allowed.`
        );
      }
    });
    
  • This trigger will reject any save request that includes fields not on your allowed list, so no new columns will be created accidentally.

3. Enable Schema Locking (Self-Hosted Parse Servers)

If you’re running your own Parse Server (not the managed platform), you can lock down the entire schema to prevent any automatic changes:

  • Add the schemaLock option to your Parse Server configuration:
    const parseServer = new ParseServer({
      // Your existing config options...
      schemaLock: true
    });
    
  • When schema locking is enabled, Parse Server won’t allow any schema modifications (including new fields) from saves. You’ll have to manually update the schema via your database or the dashboard’s schema editor if you need to add fields later. This is ideal for production environments where you want a strict, unchanging schema.

Which method you pick depends on your needs: CLPs are great for quick permission-based restrictions, Cloud Code gives you precise control over allowed fields, and schema locking is perfect for enforcing a rigid schema in production.

内容的提问来源于stack exchange,提问作者jaynp

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 07:09:11