Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [mongoose]

Mongoose is a MongoDB object modeling tool, written in JavaScript, designed to work in an asynchronous environment.

-2
votes
0answers
13 views

Mongoose populate operator not working [closed]

i know this question has been asked a lot but none of the solutions of those questions solved my problem . i am trying to join two collections and use the populate method but the populate method seems ...
2
votes
3answers
124 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 ...
0
votes
1answer
28 views

Mapping properties between two Objects of different structure

Something I've found myself having to do reasonably often is map properties from an Object (usually a heavily nested MongoDB document) to a different 'shape' to then pass it to a function call or API ...
1
vote
1answer
13 views

Saving a submitted Mongoose model, possibly with an uploaded image

I have some code which saves a mongoose model from the submitted form data. However the user might also upload an image along with the form, which needs to be saved on the server (moved from the ...
1
vote
0answers
36 views

Async API Function with Mongoose

I'm quite new to the language and I just started using async/await. I've written this function for an API that I'm developing. It checks what is sent by the user, specially the status that he wants to ...
0
votes
1answer
38 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 ...
2
votes
1answer
47 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 ...
-1
votes
0answers
146 views

What's the best way to create reference documents in Mongoose?

I have some schemas as below. The flow of creating data are User => SaleOrder => SaleItem. The SaleOrder contains the array of SaleItem, so after creating SaleItem document, I invoking ...
1
vote
0answers
34 views

Refactoring several mongoose models to similar collections [closed]

I have several collections that have the same documents type, except for the language. Let's say imagesES, imagesEN, imagesFR, and so on.... I just thought about definig just one schema, but also one ...
1
vote
0answers
332 views

post Like/Dislike with mongoose/mongodb

Right now my route is doing the following: Searching for the post by id from the request parameters Check if the user already likes the post If the user likes the post, then increase ...
1
vote
1answer
38 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 ...
2
votes
0answers
33 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 ...
0
votes
1answer
29 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 ...
2
votes
1answer
76 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 ...
1
vote
1answer
531 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 ...
1
vote
1answer
1k views

Mongoose query using conditional formatting and regex

I this the function createQuery is fully functionally, but I would like a review on it. I'm pretty sure this can be shorten and most important (improve performance). Any ideas? ...
1
vote
0answers
172 views

Exporting functions that manipulate mongoose models

I have the following code in a file called database.js which will handle all the database operations for my small application. For some background, this application ...
5
votes
1answer
132 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-...
0
votes
1answer
1k 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 ...
0
votes
1answer
69 views

Ensure every element in array passes asynchronous test

I've written a function which ensures all objects in the items array belong to the user. This involves a database check, which ...
1
vote
1answer
50 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 ...
4
votes
1answer
13k 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: ...
5
votes
1answer
125 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 <...
5
votes
3answers
221 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 ...
1
vote
0answers
97 views

Implementation of user permissions

I am building a web-application in NodeJS (using TypeScript) and MongoDB (using Mongoose). In my application I have 6 types of permissions. For the simplicity, let's use ...
3
votes
1answer
170 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 ...
2
votes
0answers
166 views

Rewrite two mongo queries to aggregation

Here is a code block I have: ...
2
votes
0answers
33 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 ...
4
votes
1answer
114 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 ...
2
votes
0answers
97 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....
1
vote
2answers
429 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 ...
2
votes
1answer
47 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 ...
1
vote
0answers
25 views

Matching a current user's “liked / followed” items with results from a search query

This is pretty ugly now. My main objective is to perform a search query, which I do via mongoosastic / elastic search (the search paginates 12 items at time). Then, I want to match those results with ...
0
votes
0answers
454 views

Generating a random ObjectID

We want to ensure that certain documents in our DB get distributed well across the shards. Currently the documents are sharded by their _id, but they are often ...
3
votes
0answers
681 views

Mongoose schema for products and social media posts

Here is my current schema: Brand: ...
1
vote
0answers
30 views

Getting data from service and storing it in MongoDB

I wrote code to get data from HTTP service and store it in MongoDB. Please, can someone let me know how efficient my code is and whether it is good from the OOP point of view? ...
2
votes
0answers
72 views

Trade off in database efficiency versus a nested for loop on client

I built an app where a user has a recipe box with recipes in it - for the db, there is a user and recipe model, user has "recipeBox" property. The recipebox is an array of objects like so: User ...
1
vote
0answers
3k views

A plugin that integrates Angular Smart Tables with Mongoose DB for server side pagination

I'm using Angular Smart Tables with data that might become a huge set of documents and rows. So rather than client side processing of the data for pagination, I borrowing code from two Mongoose.js ...
1
vote
0answers
33 views

Nesting models within models

I am saving data into a MongoDB. The data will be saved into 3 Mongoose models that are hierarchical. A User model contains an ...
1
vote
0answers
50 views

NodeJS socket for handling errors

It's the first time managing Mongoose by socket.io and I'm wondering if this could be a good way: ...
3
votes
0answers
180 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 ...
4
votes
0answers
235 views

Mongoose and Hapi/Express promise handling in controllers

I'm switching my code to promises - mostly as delivered by Mongoose. I use Hapi though I think something similar would apply to Express. In my models/services I perform queries such as: ...
4
votes
2answers
164 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: ...
4
votes
2answers
2k 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 ...
15
votes
1answer
256 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 ...
3
votes
1answer
7k 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. ...
3
votes
1answer
396 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 ...
5
votes
2answers
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 ...
4
votes
1answer
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 ...
10
votes
1answer
14k 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 ...