薄荷君
薄荷君
  • 发布:2021-05-31 15:23
  • 更新:2021-05-31 15:50
  • 阅读:1074

使用uni-admin,报“数据库验证失败:【XXX】超出范围”

分类:uniCloud

如题,这个报错原因是什么呢?代码里找不到具体的解释
使用的是阿里云的unicloud,把请求体中的字段用云数据库后台手动添加没问题,但是用页面提交就报错。
而且不是全部都有这个问题,就有几个数据提交会报错

2021-05-31 15:23 负责人:无 分享
已邀请:
薄荷君

薄荷君 (作者)

贴一下我的请求体:
{"method":"serverless.function.runtime.invoke","params":"{\"functionTarget\":\"DCloud-clientDB\",\"functionArgs\":{\"command\":{\"$db\":[{\"$method\":\"collection\",\"$param\":[\"promotions\"]},{\"$method\":\"doc\",\"$param\":[\"60b48ba71ccee70001506037\"]},{\"$method\":\"update\",\"$param\":[{\"game_id\":\"60b073ed3b7d3500015df6dc\",\"get_url\":\"\",\"shop\":\"\",\"platforms\":[],\"start_date\":1622444578948,\"end_date\":1621526400000,\"is_vip\":false,\"vip_tag\":\"\",\"is_show\":false,\"update_date\":1622447307149}]}]},\"clientInfo\":{\"PLATFORM\":\"h5\",\"OS\":\"mac\",\"APPID\":\"UNIE009394\",\"LOCALE\":\"zh-Hans\",\"DEVICEID\":\"16206149550962673036\",\"CLIENT_SDK_VERSION\":\"1.0.1\"},\"uniCloudClientInfo\":\"%7B%22ak%22%3A%22UNIE009394%22%2C%22p%22%3A%22i%22%2C%22ut%22%3A%22h5%22%2C%22uuid%22%3A%221leb6t0en9te643s18vrgt9qhs6ab7u8%22%2C%22fn%22%3A%22DCloud-clientDB%22%2C%22sid%22%3A%229abdbc99-ffd3-47d2-8054-4aeb08140e8b%22%2C%22pvd%22%3A%22a%22%7D\",\"uniCloudDeviceId\":\"16206149550962673036\",\"uniIdToken\":\"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiI2MDY2ZWIzOTcwNjM0ZTAwMDExNmRiYWUiLCJyb2xlIjpbImFkbWluIl0sInBlcm1pc3Npb24iOltdLCJjbGllbnRJZCI6IjhkNGRlMmIyN2YxNmVlMzAyNGVkNGM5MDMxZWUzY2Q2IiwiaWF0IjoxNjIyNDQ0NTU3LCJleHAiOjE2MjI0NTE3NTd9.UE3789RU-y6hxMyIA5yLqRF4sOkuk1QTqlbOJRWzHwg\"}}","spaceId":"9abdbc99-ffd3-47d2-8054-4aeb08140e8b","timestamp":1622447307205,"token":"80781636-44ef-4390-a7c8-b0b25b36bec1"}

返回体:
{"success":true,"data":{"code":"VALIDATION_ERROR","message":"数据库验证失败:[\"game_id\"]超出范围"},"header":{"x-fc-code-checksum":"14931192961446868056","access-control-expose-headers":"Date,x-fc-request-id,x-fc-error-type,x-fc-code-checksum,x-fc-invocation-duration,x-fc-max-memory-usage,x-fc-log-result,x-fc-invocation-code-version","x-fc-invocation-service-version":"LATEST","content-disposition":"attachment","x-serverless-request-id":"ac14220a1622447307268137951","x-serverless-runtime-version":"1.2.1","content-length":"115","date":"Mon, 31 May 2021 07:48:27 GMT","x-fc-request-id":"51052927-c73d-41f4-8cd4-cde1a0cb7273","x-fc-invocation-duration":"203","x-fc-max-memory-usage":"38.23","content-type":"application/json"}}

  • 薄荷君 (作者)

    找到可能的原因了:

    schema文件里,game_id 是这样的:

    "game_id": {

    "bsonType": "string",

    "description": "游戏 id,参考 games 表",

    "title":"游戏名称",

    "enum":{

    "collection":"games",

    "field":"_id as value,name as text"

    },

    "foreignKey": "games._id"

    },


    把"enum":{

    "collection":"games",

    "field":"_id as value,name as text"

    },

    删掉就好了

    但是为什么前500条数据没报错,后面的数据提交报错呢...

    同样的代码

    2021-05-31 16:12

  • DCloud_uniCloud_WYQ

    回复 薄荷君: games这个集合数据超过500条了是吗?目前enum不支持大数据量的枚举

    2021-06-02 16:19

  • 薄荷君 (作者)

    回复 DCloud_uniCloud_WYQ: 是的,超过500条了。我最后用了element-ui里面的远程搜索输入框来解决。

    2021-07-06 16:26

该问题目前已经被锁定, 无法添加新回复