I am building a filtering system and I am stuck on a problem, please keep in mind that this is demo code, this is not the same project but the concept is the same, I replaced the names to make it as easily understandable as possible. I got a filled filter object which gets sent like this (it consists of
Tag: mongoose
Moongose after find, object.map is not returning key
I have a code that after find and populate, I will then add a new key (‘order_date’) based on createdAt. I have checked with console.log(i.createdAt), it do have the date element in the i, but when I do console.log(orders), it is not retunring me order_date. Is it caused by the async await function? I am doing this because my express
How to find a document with an array of strings based on if it has items in common with a reference array of string?
Given a reference array of strings: [“Comedy”, “Horror”, “Romance”], I would like to query a Movie model with this schema: Such that I will get results where I will get Movies with categories in common with the reference array, sorted by the amount of elements it has in common with the reference array. For example: Note that Movie A is
Delete property from object in argument vs Delete property from object
Just trying to figure out some questions. context: randomFunction is a function that takes 2 arguments(id & metaData). It is a called inside a controller . The code is given below: doc contains a object (basically a document in mongodb). suppose doc contains the following: Now , in the operations file where the randomFunction is initialized. context: I wanted to
Not getting output while trying db.find() in Mongodb
Recently i have started learning mongodb and started to make a simple application that will just display the data present in my database. Here’s the code: After running this code, the data successfully gets stored in the database but it didn’t show me the output of all the data in my database. Can anyone explain how to fix this issue?
Uncaught TypeError: Cannot read property ‘collection’ of null
I’ve been trying to get data out of a collection, but it returns me Uncaught TypeError: Cannot read property ‘collection’ of null. The Mongo database itself is connected with the cloud and checking from there the collection with that name exists. I have planned to later use the output for condition check to see, if there are any similar entries.
Different types of the field _id of rows after importing data to mongodb and after the creation
I’m trying to write a JS app with MongoDB (I use MongoDB Compass). I have a schema of user: Then I import some data from JSON file like this: After the importing the type of field _id is String. But, if I create a user by method create: the type of _id is ObjectId, therefore, I can’t use methods like
Unable to refer to method `db.start Session ()` in mongoose, mongodb
When I try to refer to db.startSession () I have an error db.startSession () is not a function. In console.log I put db and I put logged variable below. Why can’t I refer to startSession()? connection controller logged variable db Answer you can do like this for using transaction in mongoose: Note:for using transaction you need to replica mongodb, so
Cast to ObjectID failed – mongoose
Hi I am trying to add an event to a users profile once they click on the event. I am getting the following error – Cast to ObjectId failed for value “{ event: ‘600066640807165d042b91dd’ }” at path “event”. The route for creating a profile and for creating an event work as expected. The 600 is the id of an event