I want to mirror the data of an external database through their API.
我想通过他们的API镜像外部数据库的数据。
However, I also want to store a few extra fields on each document. I figured the structure would be easier to reason about, if there was a clear distinction between the data supplied by the API and the extra fields I have attached.
但是,我还想在每个文档上存储一些额外的字段。我认为如果API提供的数据与我附加的额外字段之间有明显的区别,结构将更容易推理。
Example:
Schema({
youtube: {
type: Object
},
'youtube.etag': {
type: String
},
'youtube.commentThreadId': {
type: String,
index: 1
},
'youtube.channelId': {
type: String,
index: 1
},
'youtube.videoId': {
type: String,
index: 1
},
'youtube.canReply': {
type: Boolean
},
'youtube.totalReplyCount': {
type: Number
},
'youtube.isPublic': {
type: Boolean
},
lastSync: {
type: Date,
},
updatedAt: {
type: Date
},
createdAt: {
type: Date
},
});
In my case, scoping the API data on 'youtube' as an embedded document seemed to do the trick, but I would like to know if their is any performance hit by doing this, compares to having the fields at the outermost level of the document.
在我的情况下,将'youtube'上的API数据作为嵌入式文档进行定位似乎可以解决问题,但我想知道它们是否会因此而受到任何性能影响,而不是将文档放在文档的最外层。 。
1 个解决方案
#1
Organizing your data into sub-documents like this is a good idea and has no effect on performance.
将数据组织到这样的子文档中是一个好主意,对性能没有影响。
However, your schema structure is invalid because you can't have .
s in your key names. It should be defined like this instead:
但是,您的架构结构无效,因为您的密钥名称中不能包含.s。它应该像这样定义:
Schema({
youtube: {
etag: String,
commentThreadId: {type: String, index: 1},
channelId: {type: String, index: 1},
videoId: {type: String, index: 1},
canReply: Boolean,
totalReplyCount: Number,
isPublic: Boolean
},
lastSync: {
type: Date,
},
updatedAt: {
type: Date
},
createdAt: {
type: Date
},
});
#1
Organizing your data into sub-documents like this is a good idea and has no effect on performance.
将数据组织到这样的子文档中是一个好主意,对性能没有影响。
However, your schema structure is invalid because you can't have .
s in your key names. It should be defined like this instead:
但是,您的架构结构无效,因为您的密钥名称中不能包含.s。它应该像这样定义:
Schema({
youtube: {
etag: String,
commentThreadId: {type: String, index: 1},
channelId: {type: String, index: 1},
videoId: {type: String, index: 1},
canReply: Boolean,
totalReplyCount: Number,
isPublic: Boolean
},
lastSync: {
type: Date,
},
updatedAt: {
type: Date
},
createdAt: {
type: Date
},
});