2

I want to get then enteries from paris air quality, but the thing is that the mongoose schema is nested and I tried to make multiple schemas separated but I don't know wheter it's correct or not.

This is the schema file schemas/air-quality.schema.ts

import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';

export type AirQualityDocument = AirQuality & Document;

@Schema()
export class Pollution {
  @Prop()
  ts: string;

  @Prop()
  aqius: number;

  @Prop()
  mainus: string;

  @Prop()
  aqicn: number;

  @Prop()
  maincn: string;
}

@Schema()
export class Result {
  @Prop({ type: Pollution })
  pollution: Pollution;
}

@Schema()
export class AirQuality {
  @Prop({ type: Result })
  result: Result;

  @Prop()
  datetime: string;
}

export const AirQualitySchema = SchemaFactory.createForClass(AirQuality);

And the result I am getting from mongo is this PS: it contains multiple entries of the same schema

[
    {
        "_id": "62dd1b2e744e6bf8cdbcfabd",
        "result": {
            "_id": "62dd1b2e744e6bf8cdbcfabe"
        },
        "datetime": "24/07/2022, 11:13:02",
        "__v": 0
    },
    ...
]

I don't if the mistake is with the schema or I just need to use autopopulate or something

Oussama Bouchikhi
  • 527
  • 1
  • 7
  • 22

0 Answers0