I am using moment from mongorc.js (reference: https://raw.githubusercontent.com/gabrielelana/mongodb-shell-extensions/master/released/mongorc.js) when executed this small snippet its printing “invalid date” But in Java: Prints Sun Nov 30 00:00:00 IST 2 Though may not be correct, I want not “Invalid date” to be printed. Where did I go wrong? Answer I have hard coded the date value and it worked:
Tag: mongodb
How to Mongoose send different value on find of specific field
I have a field which contain url to an image which is protected. It needs a secret to access file and the secret expire after a time. I want that when I do Mode.find() then the url value get replaced by anther url which contains the secret. So, that I don’t have to manually every where I find from the
Passport.js Multiple login system is not working correctly
I am getting a weird error as all of my login system are working correctly which include local login in system and Google and Facebook login. The problem arose when I try to try to register with google when I have already register the Facebook account and I try to register Google account it gives E11000 duplicate key error collection
Impossible to query nested mongoose array?
I want to Query and array with regex inside and mongoose (mongoDB) model. I want to search inside the nested array of the Productmodel : The model inside the “suppliers” array is: Now here’s the problem, if i query and and populate() i get all the results. But for some reason I cannot search inside the Array containing several suppliers.
I am trying to use populate in mongodb with nodejs, but values are not populating
listservices.model.js Services.model.js exports.findAll = (req, res) => { const services = req.query.services; var condition = services ? { services: { $regex: new RegExp(services), $options: “i” } } : {}; Services.find(condition ).populate(‘servicescategories’) }; [{“_id”:”60a27c66d87174379c93d7b5″,”name”:”MY data name”,”closed”:false,”active”:false,”listservices”:”60a2606680405c41c05cf005″,”createdAt”:”2021-05-17T14:23:34.412Z”,”updatedAt”:”2021-05-17T14:23:34.412Z”,”__v”:0}] Answer You are trying to use different name in your controller, populate receives 4 parameters- path, selection(fields to be return) , condition, options (like {limit:10}):
Can’t upload picture to MongoDb from React frontend
I’m creating a tinder clone, I can create a user fine however I cant upload a picture. The error I get is ValidationError: User validation failed: pictures: Cast to embedded failed for value “‘picture'” at path “pictures”. I’m not sure what I’m doing wrong. The post request seems to fire as excepted with the payload however its when I login
Ignore $in if empty array is provided
I have the following model: Note: interface matches the model exactly but i pasted this as its much shorter. I am using the following data to filter through this collection: What i want to achieve is to find every document and check if the corresponding array has at least one of the values from the array i sent via includeFilters.
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: My concern is the handleError function. I’m not quite sure what kind of errors could even happen in Mongoose since it’s just a simple query, but what should be included in the handleError function? And what response should I send to
DiscordJS ticketinfo TypeError: results.transcripts is not iterable
I’m making a ticketinfo command that get’s information about a ticket that’s in my database. I’m trying to catch the information from the database and put in into my embed. The embed is being send to the user that runs that command. It seems to not work. Why isnt it working? My Code: Error: Answer It seems, that result.transcripts either
How would I access the values of the coordinates through a NodeJS MongoDB query?
Here is my query: const ships = await ais .aggregate( [{ $match: { MMSI: 219022256 } }, { $sort: { Timestamp: -1 } }], { allowDiskUse: true, } ) .project({ _id: 0 }) .limit(1) .toArray(); Answer considering the returned values you have an Array of objects (JSON objects) at your disposal, so you would be able to use the informations