var mongoose = require('mongoose');
var db = mongoose.connect('mongodb://localhost/poptest');
var authorSchema = new mongoose.Schema({
name: {type: String, default: '?'},
_books: [{type: mongoose.Schema.Types.ObjectId, ref: 'Book'}]
});
var bookSchema = new mongoose.Schema({
title: {type: String, default: '?'}
});
var Author = mongoose.model('Author', authorSchema);
var Book = mongoose.model('Book', bookSchema);
/*
// Populate the database
for(var i = 0; i < 100; i += 1) {
var books = [];
for(var j = 0; j < 25; j += 1) {
var book = new Book();
book.save();
books.push(book);
}
author = new Author({_books: books});
author.save();
}
*/
// The following takes about 12 seconds to run
var startTime = (new Date()).getTime();
Author.find().populate('_books').exec(function(err, authors) {
var endTime = (new Date()).getTime();
console.log('Time taken:', endTime - startTime);
});--
Documentation - http://mongoosejs.com/
Plugins - http://plugins.mongoosejs.com/
Bug Reports - http://github.com/learnboost/mongoose
Production Examples - http://mongoosejs.tumblr.com/
StackOverflow - http://stackoverflow.com/questions/tagged/mongoose
Google Groups - https://groups.google.com/forum/?fromgroups#!forum/mongoose-orm
Twitter - https://twitter.com/mongoosejs
IRC - #mongoosejs
---
You received this message because you are subscribed to the Google Groups "Mongoose Node.JS ODM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-orm...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
Documentation - http://mongoosejs.com/
Plugins - http://plugins.mongoosejs.com/
Bug Reports - http://github.com/learnboost/mongoose
Production Examples - http://mongoosejs.tumblr.com/
StackOverflow - http://stackoverflow.com/questions/tagged/mongoose
Google Groups - https://groups.google.com/forum/?fromgroups#!forum/mongoose-orm
Twitter - https://twitter.com/mongoosejs
IRC - #mongoosejs
---
You received this message because you are subscribed to a topic in the Google Groups "Mongoose Node.JS ODM" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mongoose-orm/lNbxx4oId_0/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to mongoose-orm...@googlegroups.com.
Thanks Aaron! That reduced my real project's page load time from over 30 seconds to 0.7 seconds.
On Tue, Apr 16, 2013 at 5:08 AM, Aaron Heckmann <aaron.h...@gmail.com> wrote:
Fixed in 3.6.5 which was just released.
On Monday, April 15, 2013 6:12:02 AM UTC-7, Robbie Clarken wrote:I have two collections: authors and books. The authors collection has a _books field which is an array of ObjectIds from the books collection. There are 100 authors and each references 25 books. If I do an Author.find().populate('_books') query it takes 12 seconds to execute. Is this to be expected?I would think that mongoose only needs to do 100 * 25 = 2500 queries for the population. This number of queries only takes 0.2 seconds when I do it through the mongo shell.Any suggestions for improving performance would be appreciated.I am running:
- node v0.10.4
- mongoose v3.6.4
- mongodb v2.4.1
Example code:var mongoose = require('mongoose');
var db = mongoose.connect('mongodb://localhost/poptest');
var authorSchema = new mongoose.Schema({
name: {type: String, default: '?'},
_books: [{type: mongoose.Schema.Types.ObjectId, ref: 'Book'}]
});
var bookSchema = new mongoose.Schema({
title: {type: String, default: '?'}
});
var Author = mongoose.model('Author', authorSchema);
var Book = mongoose.model('Book', bookSchema);
You received this message because you are subscribed to a topic in the Google Groups "Mongoose Node.JS ODM" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mongoose-orm/lNbxx4oId_0/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to mongoose-orm...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
Documentation - http://mongoosejs.com/
Plugins - http://plugins.mongoosejs.com/
Bug Reports - http://github.com/learnboost/mongoose
Production Examples - http://mongoosejs.tumblr.com/
StackOverflow - http://stackoverflow.com/questions/tagged/mongoose
Google Groups - https://groups.google.com/forum/?fromgroups#!forum/mongoose-orm
Twitter - https://twitter.com/mongoosejs
IRC - #mongoosejs
---
You received this message because you are subscribed to the Google Groups "Mongoose Node.JS ODM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-orm...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Thanks Aaron! That reduced my real project's page load time from over 30 seconds to 0.7 seconds.
On Tue, Apr 16, 2013 at 5:08 AM, Aaron Heckmann <aaron.h...@gmail.com> wrote:
Fixed in 3.6.5 which was just released.
On Monday, April 15, 2013 6:12:02 AM UTC-7, Robbie Clarken wrote:I have two collections: authors and books. The authors collection has a _books field which is an array of ObjectIds from the books collection. There are 100 authors and each references 25 books. If I do an Author.find().populate('_books') query it takes 12 seconds to execute. Is this to be expected?I would think that mongoose only needs to do 100 * 25 = 2500 queries for the population. This number of queries only takes 0.2 seconds when I do it through the mongo shell.Any suggestions for improving performance would be appreciated.I am running:
- node v0.10.4
- mongoose v3.6.4
- mongodb v2.4.1
Example code:var mongoose = require('mongoose');
var db = mongoose.connect('mongodb://localhost/poptest');
var authorSchema = new mongoose.Schema({
name: {type: String, default: '?'},
_books: [{type: mongoose.Schema.Types.ObjectId, ref: 'Book'}]
});
var bookSchema = new mongoose.Schema({
title: {type: String, default: '?'}
});
var Author = mongoose.model('Author', authorSchema);
var Book = mongoose.model('Book', bookSchema);
You received this message because you are subscribed to a topic in the Google Groups "Mongoose Node.JS ODM" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mongoose-orm/lNbxx4oId_0/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to mongoose-orm...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
Documentation - http://mongoosejs.com/
Plugins - http://plugins.mongoosejs.com/
Bug Reports - http://github.com/learnboost/mongoose
Production Examples - http://mongoosejs.tumblr.com/
StackOverflow - http://stackoverflow.com/questions/tagged/mongoose
Google Groups - https://groups.google.com/forum/?fromgroups#!forum/mongoose-orm
Twitter - https://twitter.com/mongoosejs
IRC - #mongoosejs
---
You received this message because you are subscribed to the Google Groups "Mongoose Node.JS ODM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-orm...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.