Skip to content
Advertisement

Tag: mongoose

How to query on collection values ​and referenced documents values ​in MongoDB?

I don’t know how correctly I formulated the question. I need to execute a query on both the values ​​of the collection and the values ​​of the referenced objects. The original collection looks like this: When executing a query that meets the condition district == “Texas”, I need to get the following result: Under this condition: kind == “developer”, get

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: I want to query the documents based on the ingredients that they contain. I have an array of items to search through “objectifiedIngredients”. If it has ingredients in it, then I want to search for orders that contain that ingredient. If the

How to exclude fields on return in mongoose

I have the following code: It works perfectly but say I want to exclude a field returned, like the __v field. I know I can do this by just creating an object like and etc. for teh other fields, however if I have 20 fields I don’t want to list every single one, so is there a way for mongoose

Mongoose update replace entirely former document

I’m trying to update my document to remove a few fields I am testing onto further on in the frontend, I removed the fields with this: Thus when I look at it before my mongoose findByIdAndUpdate it has indeed none of these fields then I’m trying to update like so: But when I use the overwrite option like so, it

Advertisement