Ignore $in if empty array is provided

I have the following model: export type IMangaModel = Document & { _id: string; title: string; description: string; demographic: Array; genre: Array; tags: …

Handling Mongoose Query Errors in Express.js

So let’s say I want to make a Mongoose query to a database, inside of an Express post route: app.post(“/login”,(req,res)=>{ const username = req.body.username const password = req….

How would I access the values of the coordinates through a NodeJS MongoDB query?

“_id” : ObjectId(“607ce141dfc52641ea652fb2”), “Timestamp” : ISODate(“2020-11-18T02:38:22.000+0000”), “Class” : “Class A”, &…

MongoDB get sum of fields in last stage of aggregate

I’m using an aggregate to gather some related data. The following is a sample pipeline that joins a Parent Collection to a Children One (Each Parent will have a Child). I then use a projection to …

Mongo shell query is not working on mongoose

I have written a shell query which works perfectly on mongo shell but is not returning any value when run using mongoose in nodejs + typescript; Mongo shell db.userworks.aggregate([ { $…

MongoDB/Mongoose – Find all where a specific Date is in a Date Range

for example I have documents with this field: startDate: 2021-04-14T22:00:00.000+00:00 endDate: 2021-04-19T22:00:00.000+00:00 and I want to get all documents where a specific date (like today) is in …

Node JS + Mongo DB: ValidationError: User validation failed: username: Path `username` is required because it force replaces the field

I am trying to save my data to a mongodb server but somehow it force replaces the first variable as id so it is throwing the above mentioned error. in router code I am doing console.log(req.body,cred) …

Add the sum of two fields to a new field in the document

I would like to calculate sum of two fields, then create new field in document something like: ‘totalSum’. But I dont know how to do this. All in mongodb. Here’s an example: const obj = { …

Is there a way to search through embedded arrays using aggregate pipeline in MongoDB?

I need to search through all the arrays within the categories field to find if the product belongs in the ‘T-Shirt’ category, is there a way to search through all the arrays within the category field? …

Is it necessary to use multiple Joi schema validations with Hapi?

I looked at an existing codebase and and I noticed that the codebase had two schema validations for what I feel a single schema could validate as the second schema is an offshoot of the first. See …