js data mongodb适配器仅从findAll()返回_id
我正在使用带有mongodb适配器的js data mongodb适配器仅从findAll()返回_id,mongodb,jsdata,Mongodb,Jsdata,我正在使用带有mongodb适配器的js数据mongodb。我遇到了一个问题,store.findAll只返回记录的\u id。不返回其他字段 以下是我在mongoDB中的艺术品收藏中的记录: _id: ObjectId("59bb7ee069d99027f5219667") uid :"599b73c285b13252e7f54161" title: "t1" description: "t1" imageUrl: "this.artwork.imageUrl" videoUrl: "this
js数据mongodb
。我遇到了一个问题,store.findAll
只返回记录的\u id
。不返回其他字段
以下是我在mongoDB中的艺术品收藏中的记录:
_id: ObjectId("59bb7ee069d99027f5219667")
uid :"599b73c285b13252e7f54161"
title: "t1"
description: "t1"
imageUrl: "this.artwork.imageUrl"
videoUrl: "this.artwork.videoUrl"
我的js数据存储定义的一部分:
// Create a store to hold your Mappers
const store = new Container({});
// Mappers in "store" will use the MongoDB adapter by default
store.registerAdapter('mongodb', adapter, { 'default': true });
store.defineMapper('artwork', {
collection: 'artworks',
schema: artworkSchema,
idAttribute: '_id'
});
以及我的应用程序中的代码:
store.findAll('artwork', {uid: '599b73c285b13252e7f54161'}).then((records) => {
console.log(records);
})
输出:
[记录{u id:'59bb7ee069d99027f5219667'}]
为了获得响应中返回的记录的所有字段,我缺少了什么
谢谢
更新:
结果表明,如果我从映射器中删除模式定义,字段将正确返回。这是我的模式定义。我不确定我在这里哪里出错了
const artworkSchema = new Schema({
$schema: 'http://json-schema.org/draft-06/schema#',
title: 'Artwork',
description: 'Schema for Artwork records',
type: 'object',
properties: {
uid: { type: 'string' },
title: { type: 'string' },
description: { type: 'string' },
imageUrl: { type: 'string' },
videoUrl: { type: 'string' }
},
required: ['uid', 'title', 'imageUrl', 'videoUrl']
});
啊,我真傻。findAll()
调用返回了一个包含属性的数组。console.log()
没有显示它,但我可以通过使用数组索引(记录[0].title
)或使用get('title')
来获取数据,如中所述。Argh,我太傻了。findAll()
调用返回了一个包含属性的数组。console.log()
没有显示它,但我可以使用数组索引(记录[0].title
)或使用get('title')
获取数据,如中所述