How to create time series collection in mongoDB using Nestjs and mongoose

Viewed 70

I am trying to create a time series schema using mongoose in Nestjs. Here's my schema -

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

export type NewUserModel = NewUser & Document;

@Schema({
  timeseries: {
    timeField: 'timeStamp',
    metaField: 'Name',
    granularity: 'seconds',
  },
})
export class NewUser {
  @Prop({ required: true })
  readonly Name: string;

  @Prop({ required: true })
  readonly Skills: string;

  @Prop({ type: Date })
  readonly timeStamp: Date;
}

export const NewUserSchema = SchemaFactory.createForClass(NewUser);

And here's the json request that I am sending through postman -

{
    "Name": "Nikolia Mangan",
    "Skills": "Management",
    "timeStamp": "2022-06-22T06:22:57.606+00:00"
}

This creates a collection but not a time series collection. I can confirm that by running this command in the shell -

db.runCommand( { listCollections: 1.0 } )

Which in turn returns the output -

"type" : "collection",
0 Answers
Related