Questions for mongoose


Node.js best practice for require

I am creating an Express application and using Mongoose to save data.

Why can't my kittens speak when I retrieve them from the db

Following the guide on and I´m clearly misunderstanding something basic. Why isn't the shema being applied to objects I retrieve?

Node.js and Mongoose - SEO Friendly URLs

I need to create SEO friendly URLs with Node.js, but before inserting document I'd like to check if there is already some other document which has url like that. I was searching for some module which

How to Post data with express?

I have a pretty good understanding of how to use the app.get function, but I'm having trouble with the

How to properly load-balance with Node.js / Mongoose / MongoDB + ConnectSet?

I'm using Node.js+Express+Mongoose to connect to my MongoDB replica set (3x instances).

Mongoose - Increment with findOne

I'm working on some query with Mongoose where I need to skip and limit subdocuments, but in the same query I want to increment some field in document. Currently is my query built with chaining, bec...

Using Mongoose and MongoDB, can I combine a document update using req.body and an increment using $inc?

I want to update a document using the inbound form fields from req.body without having to break them apart and build out a $set. I have this working just fine. Now I want to add an increment to a f...

Does mongoose's “distinct” function support regex in a query?

I have the following bit of js in a node/mongoose project. I'm working on an autocomplete form. It works just fine with a regular "find", but I want to do a "distinct" find instead.

How can I deny a user from logging in with mongoose-auth / everyauth

Using node.js / expressjs / mongoose / mongoose-auth / everyauth. All versions are up to date.

How to sort a populated document in find request?

I would like to sort a populated Document from the collection i fetch, i get an error requesting it.

mongoose middleware issues

the scenarios are as follows

node.js, mongoose and mongodb a pain to install :(

I'm having trouble getting these 3 packages to install and work together. Here are the steps I took:

Mongodb update with upsert and multi syntax

I am new to mongodb and so stressed out because of mongodb's incomplete documentation leaving me for trial and error... sadly, all my attempts are not working with no error, leaving me confused about

Mongoose - Count subdocuments

I need to count subdocuments of the main document. Just an example of scheme:

Mongoose schema, set key variable

I'm using expressjs, mongodb and mongoose, I'm trying to update the counts object of the following schema:

For loop in callback. Blocking?

//defining schemas, models, db connections, etc..

MongoDB creating, finding from and changing an array

Here's what I want to achieve in mongodb but as a javascript example.

JavaScript object element is missing during Mongoose update query

I'm trying to update a new field of data into an existed document, but some of the data is not updating.

Mongoose sort by child value

I have a parent and child schema that looks like:

Can't query mongoDB with mongoose in node.js

Suppose I have a collection in my mongoDB:

Callback recursive insertion Mongo with Node.js

i am doing an API with Node.js and MongoDB (Mongoose.js). And i making a "installation" script to populate the database with some example data, like users and other stuff.

Group array after unwind and match

I have a twice nested schema:

Mongoose - Proper way to initialize nested Schemas

If I have 3 models, one nested in another like below, how do I properly initialize them in my seed data function?

Cast to ObjectId failed for value “xxx” at path “_id” when aggregating with mongoose

I am trying to use aggregation based on my mongoose model. I want to aggregate amounts based on categoryId. But when trying to access via routes url, I am getting this error. (Cast to ObjectId fail...

Mongoose asynchronous defaults

It's not in the documentation, but I'm trying to figure out how to set asynchronous defaults with Mongoose. I see the model.pre("save", function(next){}) setup, but I have no idea how to mutate fie...

Removing many to many reference in Mongoose

One of my mongoose schemas is a many to many relationship:

Mongoose upsert duplicate key error

I'm trying do an upsert using Mongoose, but I'm getting a duplicate key error for the very key that should trigger the upsert.

Populate not working for an array of ObjectIDs

This is the implementation of my models :

Strange Mongoose schema.js error - `options` may not be used as a schema pathname

In my schema, if I have options in metrics : [ { options : {} } ]then I get:

Updating with mongoose, not returning any errors but neither updating

I am trying to learn CRUD with mongoose. I am only missing the update part. What am I doing wrong?

In a large Mongo collection, how do I retrieve only ID's (or any other specific property) using mongoose?

Let's say I have a Person collection, and a Car collection, and that all people have a single car, and the Person document stores the Id of the car.

Synchronous findOne with sort() in mongoose mongdb

I want to find document with the latest "sorting_index" field.

findByIdAndUpdate With Multiple Subdocuments

So I'm working with NodeJS and MongoDB, and I'm making an endpoint that lets clients update their user profiles with several optional data fields. So, one of the update queries can look like this:

Mongoose: Get full list of users

I have tried to use Mongoose to send the list of all users as follows:

Multiple Schemas in a MongoDB (using Mongoose)

I'm utilizing MongoDB, Mongoose and Node to store user information for a game.

nodejs driver for mongodb fndAndModify

I have the following code:

Mongoose error handling in one place

I found in mongoose docs that I can handle errors generally, that I want. So you can do like:

MongoDB - Populate GridFS files metadata in parent document

I am using NodeJS with Express, MongoDB, Mongoose and GridFS for uploading and retrieving files.

Mongodb/Mongoose: Filling Array of ObjectIds (references)

I have a mongodb running (MEAN environment) with two collections (users and books). One of those collections (myusers) contains an array of Objectids (references to documents of books collection) as

How to deal with nested data in Angular.js select in a form?

I have a node.js app where the form has a selector. The app loads the data from mongodb via mongoose and populates a nested referenced object. So my data looks like:

Mongoose has no connect method when loading via Browserify

I am able to load Mongoose in an interactive node session and view its connect method like so...

Mongoose ODM model creation problems

I am trying to create models in mongoose using an express app.

Mongoose nested schema CastError

I have the following data which contains a nested schema:

Cannot pull from mongoose array

In my schema I have two arrays with users, invitedUsers and joinedUsers. Invited array is created from request body

MongoDB using NOT and AND together

I'm trying to negate an $and clause with MongoDB and I'm getting a MongoError: invalid operator: $and message back. Basically what I want to achieve is the following: