Javascript RxDB在来自另一个集合的对象数组中填充数组
我正在尝试填充另一个集合中的id数组 我的JsonSchema如下所示:Javascript RxDB在来自另一个集合的对象数组中填充数组,javascript,database,rxjs,Javascript,Database,Rxjs,我正在尝试填充另一个集合中的id数组 我的JsonSchema如下所示: { version: 0, type: "object", properties: { id: { type: "string", primary: true }, // This is populated as expected working: { type: "array", ref: "othercollection",
{
version: 0,
type: "object",
properties: {
id: {
type: "string",
primary: true
},
// This is populated as expected
working: {
type: "array",
ref: "othercollection",
items: {
type: "string"
}
},
// This is where I am having problems
notWorking: {
type: "array",
items: {
type: "object",
properties: {
// This property is not being populated
problem: {
type: "array",
ref: "yetanothercollection",
items: {
type: "string"
}
}
}
}
}
}
}
从位于的文档中,我应该能够:
具有嵌套引用的示例
使用数组的示例
const myCollection=wait myDatabase.collection({
姓名:“人类”,
模式:{
版本:0,
类型:“对象”,
特性:{
姓名:{
键入:“字符串”
},
朋友们:{
键入:“数组”,
参考:“人类”,
项目:{
键入:“字符串”
}
}
}
}
});
//[在此插入其他人]
等待myCollection.insert({
名字:“爱丽丝”,
朋友们:[
“鲍勃”,
“卡罗尔”,
“戴夫”
]
});
const doc=wait humanscolection.findOne('Alice').exec();
const friends=等待myDocument.friends\ux;
console.dir(朋友);/>数组。
所以我的问题是为什么我不能访问myDocument.notWorking[0]。问题
以下是控制台的屏幕截图,可以让您更好地了解我的情况:
如您所见,
配料
属性未填充配料集合中的数据(不在图片中)。但是,将填充taxes
属性。除非使用OEM方法,否则这是不可能的
const heroes=wait myDatabase.collection({
名字:'英雄',
模式:mySchema,
方法:{
whoAmI:函数(otherId){
//从此处的其他集合返回id为“otherId”的项
返回'I am'+this.name+'!!';
}
}
});
等待英雄({
名称:“骷髅人”
});
const doc=等待英雄。findOne().exec();
console.log(doc.whoAmI());
您解决过这个问题吗?我解决过。我以为我写了答案,但显然我没有。今天晚些时候我会写一封。总之,我最终使用了ORM方法:
const myCollection = await myDatabase.collection({
name: 'human',
schema: {
version: 0,
type: 'object',
properties: {
name: {
type: 'string'
},
family: {
type: 'object',
properties: {
mother: {
type: 'string',
ref: 'human'
}
}
}
}
}
});
const mother = await myDocument.family.mother_;
console.dir(mother); //> RxDocument
const myCollection = await myDatabase.collection({
name: 'human',
schema: {
version: 0,
type: 'object',
properties: {
name: {
type: 'string'
},
friends: {
type: 'array',
ref: 'human',
items: {
type: 'string'
}
}
}
}
});
//[insert other humans here]
await myCollection.insert({
name: 'Alice',
friends: [
'Bob',
'Carol',
'Dave'
]
});
const doc = await humansCollection.findOne('Alice').exec();
const friends = await myDocument.friends_;
console.dir(friends); //> Array.<RxDocument>