Replies: 1 comment 2 replies
-
|
First, I strongly advise against creating a separate review collection per product or per store. I recommend having a single That being said, with your current setup, what prevents you from checking if a given |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I want to create a middleware function to check if the
document_Idexists and it's not wrong usingModel.exist({_id: id})or such a query, so the API throws an error.However, the problem is my models/collections are created dynamically:
Reviews-product-${productId}ORReviews-store-${storeId}let's assume the scenario of passing a
userIdto create a new dynamic model for product reviews. My code right now accepts thatuserIdand creates a model/collection namedReviews-product-${userId}based on it because it lacks the validation step.here are the functions that create the dynamic models/collections:
TL;DR when
getDynamicModelis called, it is going to check if themodelNameexists, if doesn't, it would create a new model. Nothing prevents a model with a wrong or non-existingidform being createdMaking my
Storemodel, which is not dynamic- know its product means keeping a reference to the products' ids inside it but then the whole logic of creating the models/collections dynamically has nonsense I've been trying to solve this since yesterday.Your help would be highly appreciated.
Beta Was this translation helpful? Give feedback.
All reactions