mongodb-stitch - Owner_id 字段未通过验证错误。我的架构有什么问题?
问题描述
我正在调查我的架构有什么问题。我试图在我的集合中插入一个条目,但由于我已经改变了一些东西,但我遇到了很多错误,但这似乎是我最接近成功插入文档的地方。我在 React Ionic 项目中使用 mongodb-stitch-browser-sdk 并且我有一个有效的用户登录。
我使用 StitchUser.id 作为我的 owner_id 字符串(匹配用户集合中我的有效用户的 id)。
这是我的架构,后面是 Stitch 日志中的错误。我只是想在我的目标表中插入一个文档。此外,此集合上没有过滤器,并且只有一个具有以下规则的角色。
{
"owner_id": "%%user.id"
}
这为用户提供了对他们创建的集合的读写权限。
{
"bsonType": "object",
"required": [
"goalTitle",
"startDate",
"endDate",
"owner_id"
],
"properties": {
"_id": {
"bsonType": "objectId"
},
"owner_id": {
"bsonType": "string",
"validate": {
"%or": [
{
"%%prevRoot.owner_id": {
"%exists": false
}
},
{
"%%prevRoot.owner_id": "%%this"
}
]
}
},
"goalTitle": {
"bsonType": "string",
"minLength": {
"$numberInt": "1"
},
"maxLength": {
"$numberInt": "30"
}
},
"goalDescription": {
"bsonType": "string",
"minLength": {
"$numberInt": "0"
},
"maxLength": {
"$numberInt": "600"
}
},
"startDate": {
"bsonType": "string"
},
"endDate": {
"bsonType": "string"
}
}
}
Error:
role "owner" in "todo_list.Goals" does not have insert permission for document with _id: ObjectID("5e6aa8d11d233536e3ea8604"): could not validate document:
owner_id: Does not pass validation
Stack Trace:
StitchError: insert not permitted
Details:
{
"serviceAction": "insertOne",
"serviceName": "mongodb-atlas",
"serviceType": "mongodb-atlas"
}
{
"arguments": [
{
"collection": "Goals",
"database": "todo_list",
"document": {
"goalTitle": "Test Goal",
"goalDescription": "Test Description",
"endDate": "2020-03-11",
"startDate": "2020-03-10",
"owner_id": "5e6891382e6039c1c32f7d46",
"_id": {
"$oid": "5e6aa8d11d233536e3ea8604"
}
}
}
],
"name": "insertOne",
"service": "mongodb-atlas"
}
我创建了另一个没有架构的集合,并且对 owner_id 的相同规则检查和该集合中的文档都可以很好地插入。我不得不想象这是一个架构错误。
解决方案
推荐阅读
- javascript - 根据 json 对象长度创建按钮。添加一个 onclick 属性,但不希望它仅仅因为页面加载而被点击
- python - 如何使用 python-gitlab 访问 gitlab api?
- tsql - 插入:返回插入的记录
- python - 是否有一个功能可以让我确定文本是否谈论预定义的主题?
- terraform - Terraform 从 aws_organizations_organization.main.accounts 提取帐户 ID
- python - 使用 GPIO 引脚接收 Raspberry Pi 1 上的按钮输入、通过 IP 与 Raspberry #2 Pi 通信并打开 LED 的 python 脚本
- php - 在 laravel 中添加自定义私人频道用于广播通知
- python - 如何计算导入类的不同方法执行了多少次?
- c# - 使用带有预加载函数的内存数据库对 EF Core 进行单元测试
- azure-aks - 无法提取图像 - 未经授权:需要身份验证 (ImagePullBackOff )