These are chat archives for Automattic/mongoose

21st
Apr 2015
feargal9
@feargal9
Apr 21 2015 17:47
Hey guys! I have a schema called tickitSchema. I'm wondering can I have a filed in that schema of type 'tickitSchema' ?
This is how I'm currently trying it:
dependentOn : { type : Schema.Types.ObjectId, ref : 'Tickit' },
var Tickit = module.exports = mongoose.model('Tickit', tickitSchema);
feargal9
@feargal9
Apr 21 2015 17:58
Just to clarify, this approach doesn't seem to be working. So i'm unsure if this is the best approach of using a schema within a schema
Valeri Karpov
@vkarpov15
Apr 21 2015 19:47
use mongoose.model('Tickit', new mongoose.Schema(tickitSchema)); @feargal9 a mongoose schema is a bit more than just a plain old JS object
feargal9
@feargal9
Apr 21 2015 20:23
@vkarpov15 That didn't seem to work for me, but I did define the dependentOn field like so: dependentOn : [tickitSchema]. This worked for me! I appreciate your help.
Francesco Nero
@francesconero
Apr 21 2015 23:11
Hi all! I apologize in advance for the vague question, but I'm facing a weird behaviour in my application. I'm saving a fair amount (about 100k) of documents through mongoose by using the normal save method (I need the middleware functions). Every save is preceded by a find to verify if a document already existed and is being updated or if it is a new insertion. Also documents are saved in parallel through async.map. It happens that after a about 50k documents saved, mongoose seems to freeze intermittently and saves begin to be issued very slowly (I get delays up to 3 seconds between them, when normally they don't take more than 10ms). It doesn't appear to be Mongo's fault by looking at the info provided by mongostat. I also have more than 3GB of free memory on the machine so that shouldn't be a problem as well. Could it be something related to how Mongoose works? Maybe something related to Promises? How could I debug the problem? Thanks and sorry for the wall of text.