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: var mongoose = require(“mongoose”); …

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 …

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 …

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’ }” …

Match based on a field only with non-empty array

I am trying to do a filter on something. Here is a simplified layout of my Order model: { merchant: , date: name: “Some order name&…

Using method defined in the constructor after querying document from database

UPDATE ( ANOTHER SOLUTION) What I was looking for, I found out later, was the possibility of making the method static. Then I can apply the method independently from the class. Supposing I defined …

Push object to array in mongodb nodejs [closed]

This is my mongodb collection. I want to push object to array with findOneAndUpdate(). This is my nodejs code. url = req.params.posturl filter = { url: url } update = { comments: (…

How do I refer to a nested object in .find method?

I’m writing app in node.js. In the Order model I have a “userData” object that has an “email” element. How do I refer to “email” when using the find method? order model: …

Export data from MongoDB with MongoExport and query

I’m trying to get a data which doesn’t start with “0”. This query works inside of MongoDB command line db.Hikanshou.find({“number”:/^(?!0)/}) but when I do this with mongoexport …

Adding a created date field from _id to all mongo documents

I am trying to add a new field createdDate to all existing documents using _id field. I am doing this for easy readability of the documents. I tried following snippet but it is not working. dbase….