10
votes
Checks user level and limit the data before saving it to mongoDB
According to www.lizard.ws the original's function cyclomatic complexity is 29 and for the second version is 22. Both numbers are usually considered high, and teams aim for much lower values (...
9
votes
Accepted
Checks user level and limit the data before saving it to mongoDB
I am not a mongoDB user but is there not some type of validation API, not sure if it can be used on schemes. If it can then maybe that is the better option for your code.
The Question
It have been ...
5
votes
Checks user level and limit the data before saving it to mongoDB
I would suggest to refactor the code to make it cleaner using a function that checks user level and limits
...
4
votes
Accepted
"Clean Architecture" design pattern with Node.JS and MongoDB
Your code looks very structured and nicely written, but to my understanding, your solution is not "clean architecture" (CA) as described by uncle bob. Your solution is an MVC solution.
In clean ...
4
votes
Accepted
A React - Typescript custom hook for any request (GET, POST, PUT, DELETE) to my back end
The biggest part is that the code works and it looks okay.
I only have a few concerns about unnecessary rerenders and inconsistent UI because of inaccurate status state.
Below are a few minor things I'...
3
votes
Upload .JSON product list to MongoDB and upload image to AWS S3
There's nothing outstandingly wrong, there are some minor points that can be improved.
The main concern that I have is the amount of logic happening inside the ...
3
votes
Checks user level and limit the data before saving it to mongoDB
After looking at your code for a while, I think I understood your requirements. They can be summarized in this table:
...
2
votes
Accepted
Upload .JSON product list to MongoDB and upload image to AWS S3
In general I would say the code looks fine as far as functionality, though there are a few specific points which I will mention below with more detail. The broadest critique I have is that there are ...
2
votes
Checks user level and limit the data before saving it to mongoDB
Paradigm shift: Table-driven methods
Once logic becomes complex enough, you may find it easier to manage the rules from a data structure than from code. Here's how I picture that working for you here.
...
2
votes
Simple registration with NodeJS and Mongoose
Well, the code is fairly simple, but you've made it complex due to a bad design. I would encourage the following:
Use Promises. Mongoose implements promises and so ...
2
votes
Accepted
Basic REST API for manipularing a MongoDB collection, using Node, Express, and Mongoose
This is not a full response to your question but what I could quickly jot down while looking at your post. Sorry, no insights to share. I would discourage you from choosing this answer in case someone ...
2
votes
Accepted
Is this nodejs web-application spaghetti code?
From a medium review;
The exception handling definitely raises eyebrows
ex is not defined, so ...
1
vote
Express error if agency not found middleware
I managed to accomplish this by adding the agency to res.locals. Here's the amended code:
...
1
vote
Mongoose / MongoDB schemas for blog posts and authors
You can use the forEach function like this
...
1
vote
Upload .JSON product list to MongoDB and upload image to AWS S3
I agree with Quill - 90% of the stuff in your routes should be in other files. Routes must be concise, otherwise it's hard to tell which routes you have.
Additionally, think about the processes, not ...
1
vote
Mapping properties between two Objects of different structure
Maybe I don't understand the question exactly, but what's stopping you from just creating a function to do the mapping, like this:
...
1
vote
Saving a submitted Mongoose model, possibly with an uploaded image
Your modified code is better, but you can simplify this method even more. If you don't return anything from a function in a promise, it will be resolved with no value. There's no need to do ...
1
vote
Accepted
MongoDB database connector on NodeJS
So I kind of figured this out. The db connector can be passed around like just another variable. Silly I didn't realise this before. I created a new file to abstract the model.
dbOperations.js
...
1
vote
Mongoose schema to store items from Wynncraft's API
As I see there is about 60 properties for each item in Wynncraft DB. I see two ways to improve your design:
Distribute all properties across multiple schemas: basic item information (name, category, ...
1
vote
Creating Mongoose model
You have created a good model overall and I can only suggest you some consideration.
Instead of using, created & ...
1
vote
Accepted
Send Response To Browser without DB save confirmation
The big question to ask is: what happens when it doesn’t work? (For whatever reason)
In your case, the user will probably think it worked, only to find out later that it didn’t and will most likely ...
1
vote
Accepted
Session generator/checker utility for a server
For the most part this looks pretty good, there are only a few things which I would recommend changing.
As Igor Soloydenko recommends, get rid of the comments which do nothing but restate the code. ...
1
vote
Finding multiple documents
Why aren't using mongoose .populate() method instead?
Refer to the Mongoose documentation for Population here
1
vote
Accepted
Mongoose query using conditional formatting and regex
First, using new RegExp on user input is a bit like running eval on user input (though not nearly as bad - usually). If it can ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
mongoose × 49javascript × 45
node.js × 40
mongodb × 29
express.js × 13
promise × 7
performance × 2
beginner × 2
error-handling × 2
api × 2
database × 2
asynchronous × 2
rest × 2
algorithm × 1
design-patterns × 1
functional-programming × 1
comparative-review × 1
regex × 1
security × 1
ecmascript-6 × 1
memory-management × 1
react.js × 1
typescript × 1
angular.js × 1
callback × 1