私はまた、Mongooseと一緒にMongoDBを使用して、nodejにFHIRを実装しています。 私はちょうどこの
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
フィールドがupsertingため
私のコードを、リソースを作成/更新すると、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;
}
ありがとうGrahame。ハッピーは感謝を与える。 Mongoは_idを使用します。さらに、最上位レベルにありますが、識別子サブコンポーネントの下にはありません。 – Autorun
だから、私たちが "id"と呼んでいるのと同じことだが、名前は違う? –
こんにちはグラハム、もう一度ありがとう! – Autorun