I am developing a flutter app with node js backend and mongo database.
This is the post schema
const postSchema = new mongoose.Schema({
userId: {
type: String,
required: true,
},
creator: {
type: String,
required: true,
},
createdAt: {
type: Date,
default: Date.now(),
},
title: {
type: String,
required: true,
},
breed: {
type: String,
required: true,
},
desc: String,
price: {
type: Number,
required: true,
},
views: {
type: Number,
required: true,
default: 0,
},
age: {
type: String,
required: true,
},
category: {
type: [String],
required: true,
},
phoneNo: {
type: String,
required: true,
},
images: {
type: [String],
required: true,
},
imagesThumb: {
type: [String],
required: true,
},
active: {
type: Boolean,
default: true,
},
location: {
type: {
type: String,
},
coordinates: [Number],
},
address: {
type: String,
required: true,
},
sold: {
type: Boolean,
default: false,
},
});
I want to implement a fair randomization or rotation mechanism for displaying posts in my flutter app. So that each posts get a fair chance of being shown to a wide audience.
How should I change the schema to achieve this and how should the posts be fetched?