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
Tag: mongodb-query
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 db.userworks.aggregate([ { $…
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: const obj = { …
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 …
Mongoose Subdocument in another Invalid Schema error
I have 2 separate files, one encapsulates the Slot Schema, and another for the Location Schema. I’m trying to have a field in the Slot Schema that references the location Schema. const mongoose = …
MongoDb update with ElemMatch
I have a collection that has document structure like following: Mongo PlayGround { “basicDetails”: { “id”: “1”, “name”: “xyz” }…
Find documents with array that doesn’t contains a specific value
I have the following model: var PersonSchema = new Schema({ name: String, groups: [ {type: Schema.Types.ObjectId, ref: ‘Group’} ], }); I am looking for a query that retrieves all …
Mongoose find/update subdocument
I have the following schemas for the document Folder: var permissionSchema = new Schema({ role: { type: String }, create_folders: { type: Boolean }, create_contents: { type: Boolean } }); …