These are chat archives for Automattic/mongoose

Feb 2016
Luke Childs
Feb 17 2016 10:58
Every so often the connection between our app and DB dies
we get the error :
{ [MongoError: topology was destroyed] name: 'MongoError', message: 'topology was destroyed' }
When this happens no queries will work until I restart the app
any ideas what could cause this?
Feb 17 2016 17:50
When a newly created document was just saved, and it contains references, is there a way to populate those references before passing the document through the resolved promise?
I tried this:

const partitionData = new this( settings )

    .then( data => {
        partitionData.populate( '_fields' )
        res( partitionData )
    } )
    .catch( err => rej( err ) )
Didnt work
Also tried:
return new this( settings ).save()
    .then( data => {
        data.populate( '_fields' )
        res( data )
    } )
    .catch( err => rej( err ) )
Feb 17 2016 19:47
Anyone have any clue on how to get the model name for a ref field on another model?
Feb 17 2016 21:01
@kba I'm not sure why MEAN is proposed to be the next LAMP if it works fine with simple query but basically you CAN'T make complex query (inner query/joined query). A real world project is never simple as "find the username by user_id"! Anyway now I'm not with nodejs+express+mongoose+mongodb. for this project. What's do you think is the best way to make joined query in normalized data? Maybe it's not the best for scalability, but here my numbers:30 fields per documents top
Feb 17 2016 21:14
This message was deleted
Feb 17 2016 21:25

@kba (in previous post obiouvsly I meant "Anyway now I'm ON with nodejs+express+mongoose+mongodb" ) :)

  • ~30 fields per documents top
  • ~15 refs per documents top
  • 20 supporting collections
  • ~ 1000 main documents in total (supporting collection excluded)

To be more clear you can think about this project as a OO model:

  • The father class 'CAR' have 4 type of subclass "Audi A3", "Merceded CLK", "Renault captur", "WV Golf" (some fields are in common. I'm using mongoose-schema-extend with a discriminator key)
  • each car document have refs to the 'engine vendor' collection, 'color' collection, 'market size' collection (what I call the 'supporting' collections)

I need to query and browse the CAR collections by engine vendor name, AND/OR color name, and any other document ref or text field. Ideally a json query.
The CAR collections will be not that big (as I said 1000 documents) I'm not too much worried about the performance, should I?
Any advice is more than welcome!

Feb 17 2016 21:58
Re-reading It's more clear if you think about the 'subschemas' as vendor "Audi", "Merceded", "Renault", "WV" (not a specific car model) :)