Skip to content
Advertisement

Tag: mongoose

Find objects created in last week in mongo

I have a collection which has a field called timestamp containing date object. I have this query: Also if it is possible, Can I sort these returned documents by length of an array in this document. Here is the schema: I want to sort the returned objects by size of difference of votes.up and votes.down. Right now I am sorting

Mongoose – What does the exec function do?

I came across a piece of Mongoose code that included a query findOne and then an exec() function. Ive never seen that method in Javascript before? What does it do exactly? Answer Basically when using mongoose, documents can be retrieved using helpers. Every model method that accepts query conditions can be executed by means of a callback or the exec

Mongoose date field – Set default to date.now + N days

In a mongoose schema such as: On the line for the “end” field the default date should set to +7 days. I can add presave hook and set it there, but wondering if theres a way to do this inline in the default field. Answer You can add 7 days converted to milliseconds to current date like this or even

Mongoose JS findOne always returns null

I’ve been fighting with trying to get Mongoose to return data from my local MongoDB instance; I can run the same command in the MongoDB shell and I get results back. I have found a post on stackoverflow that talks about the exact problem I’m having here; I’ve followed the answers on this post but I still can’t seem to

Mongoose auto increment

According to this mongodb article it is possible to auto increment a field and I would like the use the counters collection way. The problem with that example is that I don’t have thousands of people typing the data in the database using the mongo console. Instead I am trying to use mongoose. So my schema looks something like this:

Mongoose find/update subdocument

I have the following schemas for the document Folder: So, for each Page I can have many permissions. In my CMS there’s a panel where I list all the folders and their permissions. The admin can edit a single permission and save it. I could easily save the whole Folder document with its permissions array, where only one permission was

Multiple populates – mongoosejs

Just a simple query, for example with a double ref in the model. Schema / Model Query I already tried something like In fact only one of the populates works. So, how do is get two populates working ? Answer You’re already using the correct syntax of: Perhaps the meal ObjectId from the order isn’t in the Meals collection?

Advertisement