小编And*_*lor的帖子

具有多个 $match 或 $pipeline 条件的 Mongo $lookup

我有两个 mongo 集合,一个包含联系人又名患者,另一个包含通知。我正在尝试返回所有活动联系人状态的结果:在给定的 branchId/clinical_id 中为 true 并包括他们的已确认:错误通知。此外,我想确保联系人显示在结果中,无论他们是否有通知。

我需要通过 branchId aka Clinic_id 来“加入”集合,然后创建一个包含每个活动联系人未确认通知的数组。

联系方式:

{
  patientId: { type: String, required: true },
  clinic_id: { type: String, required: true },
  firstName: { type: String, uppercase: true, required: true },
  lastName: { type: String, uppercase: true, required: true },
  birthDate: { type: String },
  phone: { type: String, required: true },
  status: { type: Boolean, default: true }, // true - active patient
}
Run Code Online (Sandbox Code Playgroud)

通知架构:

{
  branchId: { type: String, required: true }, …
Run Code Online (Sandbox Code Playgroud)

javascript mongoose mongodb node.js aggregation-framework

5
推荐指数
1
解决办法
2078
查看次数

使用 NodeJS 将 Unix Epoch Timestamp 保存到 Mongoose Schema 类型 Date

我收到来自 Stripe API GET /invoices 端点的响应,该端点将日期作为 unix 时间戳返回。示例值为 1573917475。我需要将此值保存在 Mongoose 中的 ISO 格式中。示例:2019-11-16T15:17:55 我熟悉如何使用 Javascript 或 MomentJS 将此值转换为 ISO / UTC 格式的日期时间值。但是,如果可能,我想在 Mongoose Schema 中设置此行为。

包含时间戳值的 API 响应:

{
    "period_end": 1576509475,
    "period_start": 1573917475
}
Run Code Online (Sandbox Code Playgroud)

猫鼬架构:

new Schema({
 ... redacted ...
    period_end: { type: Date },
    period_start: { type: Date },
 ... redacted ...
});
Run Code Online (Sandbox Code Playgroud)

目前正在使用以下值保存 Mongo 中的 as 日期:

{
    "period_end": "1970-01-19T04:34:23.671+0000" 
}
Run Code Online (Sandbox Code Playgroud)

When the year is 1970 this is usually because an issue with the input date format. Can …

javascript mongoose mongodb node.js stripe-payments

1
推荐指数
1
解决办法
1609
查看次数