【发布时间】:2021-06-08 00:47:43
【问题描述】:
我正在研究领域,以使其在 Electron 中作为本地数据库离线工作。现在我想加入(聚合),所以我定义了两个模式之间的关系,但是数据没有同步。能得到帮助真是太好了。
这是我的架构:
const articleMetaSchema = {
name: 'articlemeta',
properties: {
_id: 'objectId?',
catalog_id: 'objectId?',
content: 'objectId?',
createdAt: 'date?',
description: 'string?',
main_image_url: 'string?',
origin_type: 'string?',
pub_date: 'date?',
publication: 'objectId?',
sub_title: 'string?',
title: 'string?',
updatedAt: 'date?',
url: 'string?'
},
primaryKey: '_id'
}
const articleSchema = {
name: 'article',
properties: {
_id: 'objectId?',
active_search: 'bool?',
article_meta: 'articlemeta?',
catalog_id: 'objectId?',
content: 'objectId?',
createdAt: 'date?',
flagged: 'bool?',
owner_id: 'objectId?',
rating: 'int?',
read: 'bool?',
status: 'string?',
status_updated_at: 'date?',
updatedAt: 'date?'
},
primaryKey: '_id'
}
config = {
schema,
path: getDBPath(),
sync: {
user: app.currentUser,
partitionValue: new ObjectID(getCatalogId()),
error: (error) => {
console.log(error.name, error.message)
}
}
}
let realm = await Realm.open(config)
// query
我想查询并获取文章结果,在文章模式中,我们定义了一个键“article_meta”,它是和 objectId。现在我想要文章结果,其中所有属性都带有 article_meta 作为基于 (article.article_meta = articlemeta._id) 获取的对象
预期结果:
[{ _id: '1', catalog_id: '', content: '', createdAt: '', main_image_url: '', origin_type: '', pub_date: '', publication: '', sub_title: '', title: '', updatedAt: '', url: '', article_meta: {} }, {..}, {..}]
【问题讨论】:
-
我可能忽略了这两个对象之间的关系是什么?
-
@Jay 感谢您的回复。 article_meta 是文章类型。我这样做是因为在文档中他们提到没有必要加入(聚合)两个集合。因此,为此我提到了一对一的关系。有没有办法在领域中加入两个集合?我对此很陌生。
-
嗯。
article的article_meta属性是article类型?这很令人困惑 -articlemeta是如何适应的?你能澄清这个问题吗?此外,Realm 中没有 joins,因为它不是 SQL 数据库。 -
@Jay 我编辑了它是我的错误。你现在可以重新审视它。你能解释一下关系吗?是否可以定义关系并打开同步领域实例。谢谢
-
MongoDB Realm Documentation 中有很好的信息。不过,这个问题还不是很清楚;这两个对象之间的关系与同步之间的相关性是什么?您是否有一个示例查询(无论您的联接是什么)您正在尝试这样做但不起作用?你能包括你的代码吗?请花点时间查看How to create a Minimal, Complete, and Verifiable example
标签: node.js mongodb vue.js electron realm