Здравствуйте!
Есть две коллекции
objects:
const ObjectSchema = new Schema({
_id: { type: ObjectId, required: true },
name: { type: String, required: true },
address: { type: String, required: true },
passwords: { type: String, required: true },
telefone: { type: String },
device: { type: String },
control: { type: Boolean, default: false },
});
defects:
const DefectSchema = new Schema({
_id: { type: ObjectId, required: true },
objectId: { type: ObjectId, ref: "Object" },
train: { type: String, required: true },
date: { type: Date, required: true },
time: { type: String, required: true },
causeId: { type: ObjectId, ref: "Cause" },
});
Надо.
1. Отфильтровать
defects по
date
2. Сформировать json используя предыдущий результат:
{
name,
address,
defects: [...]
}