Questions tagged [mongoose]

Mongoose is a MongoDB object modeling tool, or ODM (Object Document Mapper), written in JavaScript and designed to work in an asynchronous environment.

Mongoose is a MongoDB object modeling tool, or ODM (Object Document Mapper), written in JavaScript and designed to work in an asynchronous environment.

Documentation

Related links

To open a bug or feature request, visit: https://github.com/Automattic/mongoose/issues

For Mongoose, an embeddable web server written in C, use .

Installations

npm install --save mongoose
46587 questions
8
votes
2 answers

How do i update a user's subscription date using stripe webhooks?

I'm building a subscription plan in node.js, I read the documentation about how to subscribe a user to a plan, and it was successful. Stripe's doc states that I have to store an active_until field in the database. It says when something changes use…
Jack Moscovi
  • 2,195
  • 7
  • 30
  • 49
8
votes
1 answer

MongoDB, Mongoose - Slow query when fetching 10k+ documents

I have a MongoDB database with 10-12k documents in a collection and I'm experiencing really slow queries when attempting to fetch all documents, like this: Sales.find() .where('author').equals(author) …
Nikolay Dyankov
  • 6,491
  • 11
  • 58
  • 79
8
votes
2 answers

about mongoose populate relation a string field

I have two Schema 1 - User UserSchema = new db.Schema({ email: {type: String, required: true}, pass: {type: String, required: true}, nick: {type: String, required: true}, admin: {type: String, default: ''}, reg: {type:…
tudou
  • 83
  • 1
  • 4
8
votes
2 answers

Mongoose: Not able to add/push a new object to an array with $addToSet or $push

I use Nodejs, Hapijs and Mongoose. I 've a schema and model as follows. var schema = { name: { type: String, required: true }, lectures: {} }; var mongooseSchema = new mongoose.Schema(schema, { collection:…
Angular Learner
  • 390
  • 4
  • 16
8
votes
2 answers

Loop through Mongoose objects

I have a Mongoose result object that I'd like to loop through, but it seems to behave differently than a classic object. Usually, you can't loop through nonenumerable properties with for…in loop, but that seems to work here. Hence, that doesn't work…
Buzut
  • 4,875
  • 4
  • 47
  • 54
8
votes
2 answers

Mongoose aggregation "$sum" of rows in sub document

I'm fairly good with sql queries, but I can't seem to get my head around grouping and getting sum of mongo db documents, With this in mind, I have a job model with schema like below : { name: { type: String, …
Developerium
  • 7,155
  • 5
  • 36
  • 56
8
votes
3 answers

mongoose subdocument sorting

I have an article schema that has a subdocument comments which contains all the comments i got for this particular article. What i want to do is select an article by id, populate its author field and also the author field in comments. Then sort the…
aegyed
  • 1,320
  • 3
  • 20
  • 39
8
votes
3 answers

Mongoose not reading from Mongo secondary database

I've implemented a replica set that I'm using globally. I have my master in Oregon, US and 4 secondaries. California and Virginia, Frankfurt and Sydney. I also have web servers in those same regions as well. Those web servers connect to mongo using…
Josh Elias
  • 3,250
  • 7
  • 42
  • 73
8
votes
4 answers

Mongoose pass req object to middleware

I am writing a middleware for mongoose that gets executed for every find object using pre query hook. postSchema.pre('query', function(query, next) { // I want to access the req.user object here query.populate('Category'); next(); }); I…
Uma Maheshwaraa
  • 563
  • 2
  • 9
  • 17
8
votes
1 answer

Bulk operation by mongoose

I want to store bulk data (more than 1000 or 10000 records) in a single operation by MongoOSE. But MongoOSE does not support bulk operations so I will use the native driver (MongoDB, for insertion). I know that I will bypass all MongoOSE middlewares…
Manish Trivedi
  • 3,481
  • 5
  • 23
  • 29
8
votes
0 answers

Mongoose: How to handle versioning?

Today I came to know about versioning concept in MongooseJS(here Mongoose v3 part 1 :: Versioning). But I have question here, I like the versioning feature of Mongoose, but what should I do when my schema changes ? For example, initially my schema…
Kamalakannan J
  • 2,818
  • 3
  • 23
  • 51
8
votes
2 answers

Invalid value for schema Array path

I am trying to build comment model contains: Reply and CommentThread. CommentThread contains Reply, and Reply can recurse itself. /models/comment.js : var mongoose = require('mongoose'); var Schema = mongoose.Schema; var replySchema = new Schema({ …
invictus
  • 93
  • 1
  • 2
  • 8
8
votes
1 answer

Storing app / site settings within mongodb using mongoose

I have been developing a node.js based site which is already running successfully live and it uses mongodb as the backend storage using the mongoose. The thing is that, I want to implement some configurable settings for site (which should be able to…
HuseyinUslu
  • 4,094
  • 5
  • 33
  • 50
8
votes
2 answers

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? MY MODEL var mongoose = require('mongoose'); var testSchema = new mongoose.Schema({ name: String, number:…
Sigils
  • 2,492
  • 8
  • 24
  • 36
8
votes
3 answers

Mongoose: Returning unique result set with no duplicate entries

I am using Mongoose in a MEAN environment. How can I make sure to not have any duplicate results in my result set? Example: my database contains 10 (partly duplicate) names: Allan Allan Fourier Allan Allan Maxwell Allan Allan Foo Allan…
Igor P.
  • 1,407
  • 2
  • 20
  • 34