kotlin 作为< String>JSON模式的RealmList- Mongo数据库领域

myzjeezk  于 2022-11-30  发布在  Kotlin
关注(0)|答案(1)|浏览(93)

我有一个简单的模型类,我需要从它生成Mongo DB Atlas的模式。但是当我在JSON模式中定义RealmList<String>时遇到了麻烦。如果我将“array”作为bsonType插入,我会得到一个错误。我应该写什么来代替呢?
模型类别:

class Note : RealmObject {
    @PrimaryKey
    var _id: ObjectId = ObjectId.create()
    var title: String = ""
    var description: String = ""
    var images: RealmList<String> = realmListOf()
    var date: RealmInstant = RealmInstant.from(System.currentTimeMillis(),0)
}

当前架构:

{
  "bsonType": "object",
  "properties": {
    "_id": {
      "bsonType": "objectId"
    },
    "title": {
      "bsonType": "string"
    },
    "description": {
      "bsonType": "string"
    },
    "images": {
      "bsonType": "array"
    },
    "date": {
      "bsonType": "date"
    }
  },
  "required": [
    "_id",
    "title",
    "description",
    "images",
    "date"
  ],
  "title": "Note"
}
zqry0prt

zqry0prt1#

我不确定您使用的是哪种模式,但如果您处于开发模式,当您在SDK中添加对象时,服务器将自动生成匹配的对象,只要更改是累加性的,例如添加新对象或属性
在问题中,“images”bson定义看起来不完整

"images": {
   "bsonType": "array"
},

虽然它是一个数组,但它是一个字符串数组,所以我认为它应该看起来更像这样

"images": {
   "bsonType": "array",
   "items": {
      "bsonType": "string"
   }
}

其中项目类型定义为字符串

相关问题