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 (...
Adrian Iftode's user avatar
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 ...
Blindman67's user avatar
  • 21.7k
7 votes
Accepted

Mongoose: find() and count() query

Solution After reviewing many answers, I believe I have two options: Make two queries, like I am doing now, Use a pagination plugin for mongoose My decision was the second one and so I am now using ...
Flame_Phoenix's user avatar
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 ...
Margon's user avatar
  • 189
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 ...
Adi Cohen's user avatar
3 votes

Verifying requirements before deleting a user-parent-student-school relationship

One of the biggest things you can do to clean up you code is to simply remove the unnecessary if-else blocks. In many cases you have a return inside the first conditional, which means there is no ...
Mike Brant's user avatar
  • 9,608
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 ...
Quill's user avatar
  • 11.9k
3 votes
Accepted

'join' MongodDB collections with a for loop

The nested loops perform books.length * favorites.length iterations (up to 4 million). Instead build a dictionary of id -> rating, so total iterations max is a sum ...
wOxxOm's user avatar
  • 1,952
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: ...
Roland Illig's user avatar
  • 21.3k
3 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'...
Sean W's user avatar
  • 146
2 votes

Avoiding nested callbacks when using MongooseJS

This is due to asynchronous JavaScript, and this is called Callback Hell. You can deal with it through some design patterns, the Zoltan's answer is a really good one (way better than mine). But I'll ...
Hugeen's user avatar
  • 303
2 votes
Accepted

Avoiding nested callbacks when using MongooseJS

Yes you're right, there are better solutions. For example you could use promises instead of callbacks since mongoose operations can return promises according to the documentation. Your example with ...
Zoltan.Tamasi's user avatar
2 votes

Querying MongoDB for information on a collection of books

Use Promises. Promises will help with all the indentation, and make your code more clean and understandable in the future (believe me, you'll have no idea of what you were trying to do if you read ...
Daniel Bastos's user avatar
2 votes

Promises with Express/Mongoose to send comment notifications

I don't quite understand why you need to save notifications in the first place. It seems you could just find them on the fly when the user GET's them. That said, here's a few comments: 1: It would ...
Magnus Jeffs Tovslid's user avatar
2 votes

Verifying requirements before deleting a user-parent-student-school relationship

Rewrite Despite you explicitly asked for Promises, I'll show you my solution without nested callbacks. It was made simply by extracting those callbacks to ...
Przemek's user avatar
  • 1,212
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. ...
benj2240's user avatar
  • 1,016
2 votes
Accepted

Loading information about a competition every time the page is loaded

Is this slowing down your app by a significant amount? If not, I wouldn't worry about it. Other than that I would consider removing the custom error handling, and rather pass it on to some other ...
Magnus Jeffs Tovslid's user avatar
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 ...
Javier García Manzano's user avatar
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 ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
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 ...
konijn's user avatar
  • 33.2k
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 ...
santanaG's user avatar
  • 403
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 ...
Johntron's user avatar
  • 1,100
1 vote

Mongoose / MongoDB schemas for blog posts and authors

You can use the forEach function like this ...
Vedhagnanam's user avatar
1 vote
Accepted

Ensure every element in array passes asynchronous test

First of all, it appears that Item.findOne already returns a promise. You don't need to wrap it again in a promise. Simply use that same promise as the return value ...
Joseph's user avatar
  • 25k
1 vote

REST Server for Users using Restify and Mongoose

Few points to consider: - Extract users CRUD logic to UsersService - this service will interact with mongoose and will be responsible for create, get, update and delete operations. - Consider using ...
chenop's user avatar
  • 196
1 vote

Promises in mongoose

What I don't like in your solution In the latest version of Mongoose, save can also return a Promise. The "problem" with your code is that when you are saving you ...
Flame_Phoenix's user avatar
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: ...
Magnus Jeffs Tovslid's user avatar
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 ...
Gerrit0's user avatar
  • 3,456
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 ...
Sashi's user avatar
  • 111
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, ...
Stexxe's user avatar
  • 505

Only top scored, non community-wiki answers of a minimum length are eligible