hi, i getting this error, i cant solve it.
so i have order model like this
import mongoose from "mongoose";
const OrderSchema = new mongoose.Schema(
{
userId: {
type: mongoose.Schema.Types.ObjectId,
ref: "User",
required: true,
},
products: [
{
productId: {
type: mongoose.Schema.Types.ObjectId,
ref: "Product", // Reference to the Product model
required: true,
},
quantity: {
type: Number,
default: 1,
},
},
],
amount: {
type: Number,
required: true,
},
address: {
city: {
type: String,
},
country: {
type: String,
},
line1: {
type: String,
},
line2: {
type: String,
default: null,
},
postal_code: {
type: String,
},
state: {
type: String,
default: null,
},
},
status: {
type: String,
default: "pending",
},
},
{ timestamps: true }
);
const Order = mongoose.model("Order", OrderSchema);
export default Order;
and product model as well
import mongoose from "mongoose";
const productSchema = new mongoose.Schema(
{
title: { type: String, required: true, unique: true },
desc: { type: String, required: true },
img: { type: String, required: true },
categories: { type: Array },
size: { type: Array },
color: { type: Array },
price: { type: Number, required: true },
inStock: { type: Boolean, default: true },
},
{ timestamps: true }
);
const Product = mongoose.model("Product", productSchema);
export default Product;
i am trying to make order with same userId value , it linked with user model, and grabbing id from there, but i dont have unique field in my order model, how can i avoid this error, help please
example of order in compas
i have different project where i used to have collection with same id like here

