Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
1 vote
1 answer
154 views

Basic REST API for manipularing a MongoDB collection, using Node, Express, and Mongoose

I'm practicing back-end programming and NodeJS. As an exercise, I'm attempting to build a REST API for a MongoDB collection. I'm also learning to use the Express and Mongoose middle-wares, so that's ...
NPN328's user avatar
  • 761
2 votes
1 answer
122 views

Is this nodejs web-application spaghetti code?

I recently interviewed for a backend developer role at a startup involved in financial products, as a 2020 grad. The take-home assignment they had me submit had a few basic goals and they recommended ...
Utkarsh Pant's user avatar
4 votes
1 answer
5k views

"Clean Architecture" design pattern with Node.JS and MongoDB

After some time poorly designing my web applications' backends (mixing database calls with the controller, etc.), I have decided to try the "Clean Architecture" approach. In this example I have a ...
kibe's user avatar
  • 277
2 votes
0 answers
113 views

Modeling mongoose schemas

I'm in the process of creating my first web app using node with mongodb on the backend. I could use some opinions on the schemas/models I've set up. I have three schemas: User, Pet, Food. Here's the ...
pfinferno's user avatar
  • 447
2 votes
0 answers
113 views

Writing error handling and users routing for my JSON RESTful API

I'm currently making an app for my side project and I was looking to get some insight on the main js file, what can I improve, the error handling, what am I doing wrong, etc. I'm mostly confused about ...
Anthony's user avatar
  • 21
4 votes
0 answers
412 views

MongoDB BulkWrite - create or update a sub document within an array

I have a series of Events (roughly 10-20 events that will be dynamically created per month): Event Model: ...
Matt Carlotta's user avatar
3 votes
0 answers
88 views

Clean code: Permission with middleware

In my example, I have four models: User, Company, Project, and Plant (though my project technically has more: Plant, Job, Team, etc.). ...
Nguyen Van Tuan's user avatar
8 votes
5 answers
623 views

Checks user level and limit the data before saving it to mongoDB

I have a function that checks user level and limits the data before saving it to mongoDB database (pre 'save' middleware for mongoose). It have been getting complexity warnings and tried to rewrite it,...
Arootin Aghazaryan's user avatar
3 votes
3 answers
387 views

Upload .JSON product list to MongoDB and upload image to AWS S3

I'm using Node/Express/Mongoose to accept a JSON file containing a list of product details. These products are looped through, the images are uploaded to AWS S3, and the product is either accepted or ...
DasBeasto's user avatar
  • 155
0 votes
1 answer
63 views

MongoDB database connector on NodeJS

What my code does I am building an Express API server with mongoDB as my database. I have a list of players which must be added to 2 mongoDB collections (teamList and countryList). The data schema ...
Sashi's user avatar
  • 111
4 votes
1 answer
117 views

Mongoose schema to store items from Wynncraft's API

I am making a Schema to store items from Wynncraft's API. See an example assortment of items here: https://api.wynncraft.com/public_api.php?action=itemDB&search=a I have not finished making the ...
user avatar
1 vote
1 answer
55 views

Creating Mongoose model

I'm creating a Mongoose model for a web service. I have a secondary index on facultyId because majority of the reads would want to search by ...
abrarisme's user avatar
  • 278
2 votes
0 answers
44 views

Javascript RPC Call Handles Data and Returns DB Response

I have a service within a larger set of microservices that's handling a RPC call. My function mainly just parses through the request, uses the data to insert data into our MongoDB database, and then ...
abrarisme's user avatar
  • 278
0 votes
1 answer
40 views

Send Response To Browser without DB save confirmation

Just reviewing my own code and noticed that I'm saving info in the DB and WAITING for that to respond before I send info to the browser, although I'm wondering if it would be more performant to not ...
TJBlackman's user avatar
2 votes
1 answer
107 views

Session generator/checker utility for a server

I wrote a utility for generating and saving sessions in a MongoDB database as well as checking the session to make sure it's valid. I'm a beginner when it comes to promises and I have a feeling that ...
Acontz's user avatar
  • 123
1 vote
1 answer
1k views

Finding multiple documents

I wrote a Mongoose Node/Express application. I have 4 documents. I am trying to write a route (end point) to get all seats for a table with their full data. I get a response like I expect. I want to ...
Alin's user avatar
  • 121
5 votes
1 answer
166 views

Simple registration with NodeJS and Mongoose

I'm new to Node.js (and also backend) for only a week, and now I'm trying to do a simple registration. I found that it's really hard to reduce complexity because pretty much every callback is error-...
Rookie's user avatar
  • 51
2 votes
1 answer
5k views

Mongoose / MongoDB schemas for blog posts and authors

I'm programming a model for a blog with authors and posts. I was following this doc: Mongoose Query Population My concern is that the createPost function is inefficient. Another option is to nest ...
masterjohn12's user avatar
1 vote
1 answer
64 views

Loading information about a competition every time the page is loaded

I am using KeystoneJS to manage data and my APIs (which includes Node.js, MongoDB, and Express.js). It uses Mongoose to connect with MongoDB; Keystone queries are essentially the same as Mongoose ...
user avatar
9 votes
1 answer
38k views

Mongoose: find() and count() query

Background I have a query in Mongoose that finds a set of objects, and then returns these said objects together with the total number of them: ...
Flame_Phoenix's user avatar
5 votes
1 answer
176 views

Promises with Express/Mongoose to send comment notifications

I'm building the backend for a mobile app project. Below is my createComment controller. The challenge for me is that I want to send notifications out to the <...
bloppit's user avatar
  • 171
5 votes
3 answers
229 views

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

I am new to node, after I finished my APIs I realized that all of them are a mess, and are a callback hell, this forced me to learn about promises, now it was all good until I faced an API that has ...
motchezz's user avatar
2 votes
1 answer
212 views

REST Server for Users using Restify and Mongoose

I am creating a REST API to access a database of users. I am new to Node.js and developing REST APIs in general. I am also trying to use best security practices. main.js ...
carloabelli's user avatar
2 votes
0 answers
175 views

Rewrite two mongo queries to aggregation

Here is a code block I have: ...
Nazar's user avatar
  • 71
2 votes
0 answers
47 views

Storing products in MongoDB with support for sorting by their number of followers

I'm loading products via an infinite scroll in chunks of 12 at a time. At times, I may want to sort these by how many followers they have. Below is how I'm tracking how many followers each product ...
NoobSter's user avatar
  • 193
4 votes
1 answer
285 views

Promises in mongoose

I've implemented a promises in mongoose to reduce the amount of callback hell but I am not sure whether my technique is correct. The scenario: Before I can save my schema I want to run some ...
Lorenzo von Matterhorn's user avatar
2 votes
0 answers
151 views

CRUDL actions on MongoDB collection using Mongoose and NodeJS

I am using Mongoose ODM and NodeJS to implement CRUDL operations on MongoDB for further use with REST API. Initially, I've implemented functions using Promises but then switched back to callback style....
Eugene's user avatar
  • 121
1 vote
2 answers
994 views

Avoiding nested callbacks when using MongooseJS

I'm diving into the world of nodejs and mongo. I am playing around with a simple app that uses MongooseJS to talk to Mongo. I have been looking at examples and some GitHub projects for references, but ...
user avatar
3 votes
1 answer
53 views

'join' MongodDB collections with a for loop

This is a very simplified version of my query. Is it acceptable to join the two collections for the client with the use of for loops? There could be up to 2,000 books, which also means there could be ...
NoobSter's user avatar
  • 193
4 votes
0 answers
2k views

Mongoose schema for products and social media posts

Here is my current schema: Brand: ...
NoobSter's user avatar
  • 193
3 votes
0 answers
184 views

Beginner's To-do app with Node.js

I get the feeling the code for this to-do app is not secure. I am just a beginner, and I don't know much about coding style so do you think it is conventional/elegant? Please don't hesitate to ...
user avatar
4 votes
2 answers
179 views

Querying MongoDB for information on a collection of books

I have this huge chunk of code. Is there any better to write this code, or am I too paranoid that I check every MongoDB query for error? The logic is here: ...
Tim's user avatar
  • 337
4 votes
2 answers
3k views

Node.js script may have memory leak

I use this node.js script to migrate MongoDB collection to a schema to another. It does work if the collection is <20k documents, but slows down to a crawl and sometime throw a FATAL ERROR: JS ...
DrakaSAN's user avatar
  • 210
15 votes
1 answer
295 views

Making an efficient and healthy db call for a real-time browser game

I'm doing a calculation for a real-time browser game, where users can invest some of their balances to the site. I need to update their invest's based on ...
Lazy's user avatar
  • 163
3 votes
1 answer
8k views

Mongoose promise & error handling

I search for rails-like way of writing NodeJS code and it's more then hard to find the right way. The code quickly become bloated and unreadable. I would like my code to be as clean as possible. ...
xpepermint's user avatar
3 votes
1 answer
422 views

Controller code using the koa framework

I would like to gather ideas on how to refactor the JavaScript/NodeJS controller code below to be more aesthetic. The code is using the koa framework thus I use ...
xpepermint's user avatar
5 votes
2 answers
2k views

RESTful API for Todos using Hapi

My goal is to create a simple restful api that will be accessed by an AngularJS front end. Even though it's fairly simple, I'd like understand how to make it more reliable, secure, and best-practices ...
jrmce's user avatar
  • 53
4 votes
1 answer
2k views

Optimizing async joins for mongodb (mongoose) using async.js

I'm building a media viewer web app for a kiosk in node that uses data in mongo. To render the viewer, it gathers together all the Asset objects (representing video files), each of which belong to a ...
Luc's user avatar
  • 41
12 votes
1 answer
19k views

Seeding MongoDB using Mongoose models

I'm using mongoose to seed a mongodb database based on my mongoose models. I'm particular interested in improving the seed code. I have two models, an article and a category. The relationship between ...
Gerard Downes's user avatar