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
Tag: mongodb
Blaze template, loop through fields?
I have been unable to find reference to any shortcut that might be available to loop through fields that are named “week01”, “week02”, “week03” where I could reference the field which is an object containing child fields in the same structure. I know of #each for each document but don’t know how to go about each field. I have 30
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?
Mongo DB aggregate $lookup slow add index to all documents?
I’ve got two collections in my Mongo DB database. I’m quite new to Mongo DB in general. Each of my collection says that there’s 1 index, now, coming from a Laravel and SQL database where I can improve performance by adding an index with ->index() on my migration for my columns, I assume there’s a way to do something similar
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
Can’t Push data One to Many Relation (nodejs ,mongodb)
I am trying to insert data into MongoDB database but I get this error Cannot read property ‘push’ of undefined. I can’t understand what is the issue is here in my code. please help me with the solution. I am a Student and learning it. here I am trying to push service into the category Model. for that, I have
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
Filtering, mapping and sorting documents in aggregation pipeline
Lets say I have an aggregation pipeline, and I am being able to get the required details as needed but I need to sort values of key named visits in descending order and then cherry pick items in it. Sample response Now, what I am looking for is to arrange the visits field in descending order based on _id. And