I'm still a beginner in Nextjs I get range error when i try to fetch products from database, ihave the same exact code for categories with no problem at all...
this my nextjs server action:
export async function getProducts() {
try {
connectToDB();
return await Product.find({});
} catch (error: any) {
throw new Error(`Failed to catch products : ${error.message}`);
}
}
this is from my client side:
const getAllProducts = async () => {
try {
const response = await getProducts();
console.log('response: ', response);
setProducts(response);
} catch (error) {
console.log(error);
} useEffect(() => {
getAllProducts()}, []);
can someone tell me whats wrong here i see no loops and i have the same exact code literally for categories section no problems at all
let isConnected = false; export const connectToDB = async () => { mongoose.set("strictQuery", true); if (!process.env.MONGODB_URL) return console.log("Missing MongoDB URL"); if (isConnected) { console.log("MongoDB connection already established"); return; } try { await mongoose.connect(process.env.MONGODB_URL); isConnected = true; console.log("MongoDB connected"); } catch (error) { console.log(error); } };
– Confessor