I have a Cheques and a Payees collection, every cheque has its corresponding Payee ID. What I’m trying to do is to write some queries on cheques, but I need to preform the searching after populating the payee (to get the name) I guess what I’m trying do is fit this somewhere in my code, I have tried to put
Tag: mongodb-query
Mongodb: How to group the result of a $lookup and map them to a list objects that contain a matching key?
I have classroom document which contain ‘modules’, the whole document looks like this: I also have assignment documents as such: My question is how could do aggregation such that if I want to do a lookup on the assignments for the classroom, I am able to group the assignment documents by moduleId and then add them as a field to
Mongodb Compare two fields with ratio
Rows whose field is twice that of the other field explain with example : I want row that spend is equal or bigger twice price (spent >= 2*price) result : {id : 1 , price : 40 , spent : 90} ==> (spent >= 2price) [90>80]* {id : 1 , price : 80 , spent : 200} ==> (spent >=
MongoDB match expression query not working
MongoDb query match expression not working. I have a posts collection and want to return only those posts which match the user Id of the user who created it but my query does not seem to be working. Sample Dataset MongoDb Query:- Query Output:- The query does not work output contains posts created by all users it is not filtering.
How to backup a mongodb database with authorization enabled?
I am running a mongo database on Digital Ocean. I’ve set it up with the following tutorial: Mongodb setup and secured it with this tutorial: MongoDb security Now I am trying to create a dump of a particular database. I am using the following command as stated in this article: Backup & Restore Mongodb: sudo mongodump –db dbName –out /var/backups/mongobackups/date
How do I get the same parent result regardless of the order of children being queried? (One to Many)
I’m building a chat with private rooms. What I’m trying to do is find a room that two users belong too. If there isn’t one create one. Chat Schema Query Controller The problem I’m having The order of the auth and receiver changes depending who is logged in and produces a different query result for chat. For example: Example One
Mongo shell query is not working on mongoose
I have written a shell query which works perfectly on mongo shell but is not returning any value when run using mongoose in nodejs + typescript; Mongo shell But when I run the same query using mongoose in one of my routes. Mongoose : I would really appreciate if someone could help me with this. Because it took me a
Add the sum of two fields to a new field in the document
I would like to calculate sum of two fields, then create new field in document something like: ‘totalSum’. But I dont know how to do this. All in mongodb. Here’s an example: Answer Demo – https://mongoplayground.net/p/40DnYmMnEyU Use $addFields to add new fileds total, compute values using $add Output
MongoDB: $function operator does not support arrow function
I have following documents in testCollection: I am using regular expression to filter documents using $function operator. I get the correct output while using Query 1. Query 1: Output for Query 1: but for Query 2 I am getting all the documents and the filter is not working. In Query 2 I changed the function body to arrow function. Query
Uncaught TypeError: Cannot read property ‘collection’ of null
I’ve been trying to get data out of a collection, but it returns me Uncaught TypeError: Cannot read property ‘collection’ of null. The Mongo database itself is connected with the cloud and checking from there the collection with that name exists. I have planned to later use the output for condition check to see, if there are any similar entries.