I’ve ran into a bit of an odd issue with a mongoose result. I can select one value from the object, but not another. For example I’m calling I get a result and im console logging out the entire product. The result is: I can log out the storePrice field However if I try to log out the dropDate and
Tag: mongodb
How do I use $addToSet with objects in mongodb?
I want to push only unique objects into an array with $addToSet. My userSchema has a field bankDetails which should take an array of objects: I am updating the schema using the following controller function: The data is saving correctly but Mongo auto generates an _id field every time so technically none of the objects are unique and the objects
How to perform user-input validation using if statements
I’m trying to perform user validation using if statements but on testing using post man, I keep on getting only the first return statement ‘Email is required ‘ even after adding a valid email address and also an invalid email address. I have attached the user model, user controller logic and a picture of postman’s response user schema model user.controller.js
RegExp not working in prisma aggregateRaw for MongoDB
I’m new to mongo and prisma in javascript. This is a mongo query using prisma’s aggregateRaw method. The cond should do a case-insensitive string comparison. For example if $$property.property_name is “The Brough”, a regex /the br/i should be true. Prisma throws an error it doesn’t like the RegExp or /regex/ notation. This same query works from mongosh command line though.
Data Format, how to map this object?
I’d like to map out an array from a backend API call. This comes from a schema which currently has the format of Within this, I have an object, however it looks like this for example: Given the above, i’d like to map through this data on a component. I have tried to store it into a const, then map
How to add new value with same key to document
I need to write down a category and its cost in category object. Now, in my code example, I am adding the products: $50 category to the user. After execution, ‘categories’: { products: ’50$’ } is displayed in the console. But if you add products: 1000$ again, it will overwrite and output ‘categories’: { products: ‘1000$’ }. And I need
How to get a boolean value if a location coordinate is within the given $geoWithin or $geoNear radius in mongoose?
I want to get a boolean value eg. true or false if a location coordinate is within the given radius is the $geoWithin query or $geoNear pipeline in mongoose aggregate function. If I user $geoNear in the mongoose aggregate pipeline then it only returns the filtered result. So far I have done the following, The Model: The function in my
MongoDB – How to use arrayFilters in pipeline-style for update
I use Mongo 4.4 and I try to perform an update with the aggregation pipeline using updateOne that updates the nested array elements. In order to update the specific array member I use an arrayFilter in the option but for some reason, I get the error message: arrayFilters may not be specified for pipeline-style updates. The query is something like
Sort the array of database object-id
I have a array of mongodb object-id and i want to sort them in such a way that similar IDs are next to each other example : Input : var array = [“507f191e810c19729de860ea”,”00000020f51bb4362eee2a4d”,” 507f191e810c19729de860ea”] Output : var array = [“507f191e810c19729de860ea”,”507f191e810c19729de860ea”,”00000020f51bb4362eee2a4d”] Answer Simply sorting the input array would result in the same input array being sorted in natural order (converting the
MongoDB attribute to array migration script
I’m trying to make a migration for a database, which has the following structure as of now: There have been some changes in how we need to handle a site, having now the possibility to have multiple sites, and not only one. So I need to change the DB to look like this: Is there a way to change the