【问题标题】:Data type for an array of Object in realm - react-native realm领域中对象数组的数据类型 - 反应本机领域
【发布时间】:2021-08-05 07:13:16
【问题描述】:

我正在使用 React-native 的 Javascript 领域

我想生成一个领域模式来保存一个 Object 数组,如下所示:

arrayOfObj:[{ key1:1111, key2:2222, key3:333 }]

到目前为止,我尝试的是在我的架构中使用 mixed 类型

const mySchema = {
    name: "mySchema",
    properties: {
        _id: "objectId",
        arrOfObj: "mixed" //'have used mixed[] too but they all don't work
    }
}

我尝试过使用 mixed 和 mixed[] 但是当我尝试插入对象数组时出现错误:mySchema.arrOfObj must be of type 'mixed?[]', got 'object' ([object Object])].

现在,领域中对象数组的正确数据类型是什么?

【问题讨论】:

  • 混合类型似乎仍处于测试阶段github.com/realm/realm-js/releases/tag/v10.5.0-beta.1
  • 你想在数组中存储任何数据还是你知道数据的结构?
  • @MichaelBahl 我想将 一个对象存储在一个数组中,其键值对为 ObjectId: Integer,类似于 [ {'60b6c1381d5d2f2afe4b3b' : 2, '51b6c15a1d7d6a2ba99a6c' : 3} ]
  • @MichaelBahl 你能提供一些帮助吗?

标签: react-native realm mongodb-realm


【解决方案1】:
const myScheme = {
  name: "myScheme",
  primaryKey: "_id",
  properties: {
   _id: "objectId",
   _partition: "string",
   name: "string",
   tasks: "myData[]"
 }
};

const myData = {
  name: "myData",
  primaryKey: "_id",
  properties: {
    _id: "objectId",
    _partition: "string",
    firstname: "string",
    lastname: "string",
 }

};

【讨论】:

  • 这会创建一个单独的myData物理对象,如何让它保存在myScheme里面?
猜你喜欢
  • 2016-03-20
  • 2017-04-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多