学习FHIR并尝试实现使用MongoDb作为数据库的均值堆栈,我想在我的问题上寻求您的帮助。
当我收到一个新资源文档的POST请求时,我会将它插入到MongoDB中。因为MongoDB会将_id (对象id)作为唯一id添加到资源。当我检索文档时,它将有一个额外的字段_id。我认为这将使资源不再合规,因为_id没有在资源中定义。
我可以知道如何处理这个问题吗?这个额外的_id会在冷杉资源中起作用吗?
致以最好的问候,自动运行
发布于 2017-02-03 17:14:07
因此,我也在使用MongoDB和mongoose在nodejs中实现FHIR。我刚刚在mongoose的模式定义中添加了一个名为id的字段,如下所示
import mongoose from 'mongoose';
import shortid from 'shortid';
class resource extends mongoose.Schema {
constructor(schema) {
super();
this.add({
// just added this to make MongoDB use shortid
_id: { type: String, default: shortid.generate },
id: { type: {} },
id_: { type: {} },
implicitRules: { type: String },
implicitRules_: { type: {} },
language: { type: String },
language_: { type: {} },
...schema
});
}
}
export default resource;然后,在创建/更新资源时,_id字段从id中获取其值
我用来插入患者资源的代码
upsert(root, params, context, ast) {
const projection = this.getProjection(ast);
if (!params.data.id) {
params.data.id = shortid.generate();
}
params.data.resourceType = 'Patient';
const upserted = model
.findByIdAndUpdate(params.data.id, params.data, {
new: true,
upsert: true,
select: projection
})
.exec();
if (!upserted) {
throw new Error('Error upserting');
}
return upserted;
}发布于 2016-11-20 14:47:02
是的,_id将不符合。你不能把它改成“id”吗?
发布于 2016-11-21 17:30:23
也许您可以看看Spark server,它也使用MongoDB来存储资源。在Spark.Store.Mongo命名空间中,您将看到一些助手方法,用于将Mongo BSONdocument转换为FHIR资源。
https://stackoverflow.com/questions/40701191
复制相似问题