Type Error : Cannot read property ‘name’ of null [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. Want to improve this question? Update the question so it’s on-topic for Stack Overflow. Closed 7 days ago. Improve this question i am having a problem with my nodejs server connected to mongoDB this is the main code for app.js That is my main routes and the problem i am having is using the last route for the /campgrounds/:id on the show page i am just trying to call and it just returns this error: TypeError: /mnt/c/Users/zhelf/Downloads/test/yelpcamp/views/show.ejs:4 2| 3| 4| <%= campground.name %>

MongoDB: How to append to a string in a deep nested array

I’m a hobbyist web programmer who just started learning MongoDB/Mongoose and I can’t seem to figure out how to append to a string located in a deep nested array. I am trying to append a string to the end of hours: String. Below is the Schema I’m working with: Here is what I have so far. I tried to extend upon this answer here: https://stackoverflow.com/a/56589089 .But this is giving me a Cannot specify arrayFilters and a pipeline update error. Edit: Below is code with which I created an instance of the model Here is a screenshot of the data in

findOne not working? mongoose / mongodb server

basically a user has properties {_id: objectid, username: string, password: string, .. etc} I send this route a json like below to change its username Assume Admin123 doesn’t exist then const foundUser would not be null because there is no user in the user collection with username Admin123. However const foundUser is never null? I’m not sure what I am doing wrong Answer Hay there, How about a smaller solution I’m giving you that to just make your code better What’s wrong with your code ?? You are querying the same user twice! You are in the hill of callback

How to exports many mongoose models modules in node.js

I have 2 models like this Now I want to export them. First I export Db and everything is fine. I can do an HTTP request with it. However, when I try to export ´the 2nd one outside, it stops functioning. The functions below will return a blank JSON file as a response. This won’t work either. It returns an error handler saying all my functions in the handler is not function. This is the function on the file I import the models. The return from the handler is Db.findOne is not a function. Is there any way to export

How to insert documents if they don’t already exist from within a remote method in MongoDb using LoopBack

I’m very new to MongoDB (about 4 days in) and I’m trying to insert documents into my collection from within a remote method using Loopback without adding duplicate documents. I firstly tested adding documents as such: Which worked without issue. I then moved on to trying to add a document without adding duplicates a few other answers: However, this did not add anything to the database. I decided to move on and try and see if I could first check to see if a document could be found from a collection and therefore not add the document. Similar to this

Automatic Random Test Data Generation of Documents for Seeding a MongoDB Database

I’m using JSON Generator https://next.json-generator.com to seed my MongoDB database. I’m finding trouble to generate a random set (from one to six) of colors out of the predefined group. I’ve succeeded to generate all of the other property values but color. I need for the availableColors key to generate a random variable number of colors out of a predefined set of six: “blue”, “brown”, “green”, “white”, “yellow”, “gray”. Here is the URL to the online generator where it is possible to real-time edit it: https://next.json-generator.com/E1g60a1pL Here is the code: Here is the result I get: I expect the “availableColors” of

MongoDB (JS), do query opperations on one document property if available, else take other property

So let’s say I have following documents in my “Request” collection: The goal is to diplay to the user a sorted list of requests by distance from his position from nearest to farest. If pickup.coords is available it should take that as position reference for follow up expressions, else take meetup.coords. I tried using $cond but I get an error and I’m not sure how to use it exactly. Here is what I thought could work: Error: unknown top level operator: $cond The request will be much more complicated at the end, because I will do some pagination with limit

When to close MongoDB database connection in Nodejs

Working with Nodejs and MongoDB through Node MongoDB native driver. Need to retrieve some documents, and make modification, then save them right back. This is an example: With asynchronous nature, if the process of updating the document takes longer, then when cursor reaches the end of documents, database connection is closed. Not all updates are saved to the database. If the db.close() is omitted, all the documents are correctly updated, but the application hangs, never exits. I saw a post suggesting using a counter to track number of updates, when fall back to zero, then close the db. But am