I want to find only 20 Parent records in LIFO order if it has more than 5 children. Children is a different table. Highly appreciate your help!
Parent table name - Content
import { model, Schema, Model, Document } from "mongoose";
const ContentSchema: Schema = new Schema({
userId: String,
contentType: String,
},
{ timestamps: { createdAt: 'createdOn' } }
);
export const Content = model("Content", ContentSchema);
Child table name - Transaction
import { model, Schema, Model, Document } from "mongoose";
const TransactionSchema: Schema = new Schema({
contentId: { type: Schema.Types.ObjectId, ref: 'Content' }
},
{ timestamps: { createdAt: 'createdOn' } }
);
export const Transaction = model("Transaction", TransactionSchema);