Add AllowDiskUse (true) to the aggregation

I am getting a 'sort exceeded memory limit...' error which dictates using allowDiskUse(true) in my aggregate. My problem is that I can't quite figure out where to add that to my code. I have tried adding it as an object within the pipeline and as a p

Mongoose / MongoDB - Delete and insert in one transaction

I wanted to delete certain set of documents in the mongo collection and insert new records, in case if the insert fails I want to rollback the delete. Basically, it is either both or none. Someone know what is the best approach for this. I'm using mo

findOne query compare date in utc

I am using UTC date format in my application and storing the data as shown below { "_id" : ObjectId("58ef69c221f24305c0c7123b"), "departmentId" : "58db361424f6bc2d3840f38b", "departmentOfficerId" : "5

Query a result returned by mongoose in nodejs

I am relatively new to Node.js, Mongoose and MongoDB. I want to perform filter functionality and want to filter products by criteria selected by the user. Is it possible in Node.js to query a response returned by Mongoose? Sample response from Mongoo

mongoosejs gets _doc without loop

I have a question after performing a find() in mongoosejs. Is there a better way of just getting the _doc-object without looping through the whole queryresult? I'm searching for something like model.getDoc() but I can't find it. ThanksOk, I found a s

How to avoid duplicates in the mongoose

I'm creating a new schema in mongoose and trying to take input from user. I want that no duplicate entry is getting updated for serverIP, for that unique : true is added. But this is not working as expected and duplicates entries are getting through.

Mongoose $ is any value

Based on user input I want to search my db for documents where the type is one of several values. If the input is equal to 'any', I want to it to return documents where the type is equal to anything. My $match is part of an aggregate pipleline. I jus

Update a document without deleting existing values

I have movie model which is referencing a user model by object id. A user can add or remove itself from the attending list and I'm trying to implement it using mode.findOneAndUpdate. I read that I should add $set the existing attending user won't get

Retrieve data based on mongodb date

I have created an app with 2 models where the match refer to a specific league. From this I wan't to make a query to get all leagues which has upcoming matches. How can I do this or should I change the structure of my models? I've tried to make a que

Mongoose optional search query parameters?

I have a following situation. I need to build a mongoose query, based on certain arguments if present. I.e. if object like this is passed { player: "nickname", action: "capture" } the following search is performed: Entry.find({ player:

q.all () to solve several Mongoose queries simultaneously

I am trying to use the q promise library to run two mongoose queries concurrently. I wish to make the two queries independently, then execute a function using the results after both queries are complete. I attempted to set up q.all() this way, but th

MongoDb full text search AND condition

I try to use text-index in mongodb: {$text: {$search: 'sport hockey'}} Is uses OR condition for searching by phrase: 'sport' OR 'hockey'. For example the result can be the following list of titles: Sport something today... Sport is hockey Hockey play

Mongoose returns indefinite for an existing field

After a mongoose request I have my document doc which is the result of the query Here is the schema used var searchSchema = new mongoose.Schema({ original : String, images : [String], image: String }); The model : var searchModel = mongoose.model('Se

Mongoose: How to Get a Query String Representation

I implementing module who automatically generate mongoose query by requested params, so for simplified test process I need to be able to get text representation of final query. How could I do that? Like we have something like this: var q = AppModel.f

How to exclude certain fields from the document

I have the following simple shema: var userSchema = new Schema({ name : String, age: Number, _creator: Schema.ObjectId }); var User = mongoose.model('User',userSchema); What I want to do is create the new document and return to client, but I want to

Many-to-many mapping with Mongoose

I have FlashcardSchemas and PackageSchemas in my design. One flashcard can belong to different packages and a package can contain different flashcards. Below you can see a stripped down version of my mongoose schema definitions: // package-schema.js

Apply getters on a & ldquo; find & quot; request in Mongoose?

Sorry if this has been asked before (I've searched, honestly). Basically, I have a simple schema: var ProductSchema = new Schema({ name: {type: String}, image: {type: String, get: getImageUrl}, stock: {type: Number}, price: {type: Number}, descriptio

Show errors with node.js

I want to be able to send a friendly error message to my user whenever I cannot connect to my MongoDB server from inside node.js, instead of just having node.js freaking out as it does right now. Apparently this won't work as I cannot access the resp