These are chat archives for Automattic/mongoose

11th
Feb 2016
antonioaltamura
@antonioaltamura
Feb 11 2016 01:31
@vkarpov15 I see around mongoose there are many useful modules for make faster the development of a rest api like express-restify-mongoose and mongoose-autopopulate..and I found them both just for case!
Maybe you can advice some other stable and useful modules for the community here :) ?
In my case please note I'm developing a rest webservice, a public user interface (html+ajax) attached too. The particular features of my project are:
  • high amount of fields per document (20-30)
  • many refs per document (simple refs, array of refs, array of embedded document with refs in it)
  • schemas with refs that references itself
  • the high amount of fields per document is taking me to think a good way for generate the frontend forms for POST/PUT actions (a the complex form, see points above).. no answer so long
Konstantin Baierer
@kba
Feb 11 2016 11:20
@jhyland87 Yes you can put all the methods in some other place and assign them to statics or methods in one place (e.g. a loop as you propose). You need to make sure that the context is kept in the actual call though, using bind, apply or similar to guarantee this refers to what it should refer to.
Chris Paradeise
@cparadeise
Feb 11 2016 16:50
Scenario: I've got two collections. TripLogs and TripDatas. TripLogs contain the LogID, DeviceID, RouteID, Direction, StartTime, EndTime. TripDatas contains LogID, DeviceID, other specifics for that particular stop / event. How can I group datas by LogID + RouteID + DeviceID + Direction without rewriting the schema?
Direction is inbound and outbound
My task is to display a summarized view of Route data
a device is basically a Bus
Chris Paradeise
@cparadeise
Feb 11 2016 16:55
TripID also exists on the TripLogs
but not on the TripDatas...
should I scold the narwhal that created the schema?
Renader
@Renader
Feb 11 2016 17:59

hey guys. I have two schemas one for "Productions" and one for "insurances". the relation is one to one. Productions have a status field. Insurances have a ref to the Productions ID. Now i want to find Insurances, BUT only if the status of the production equals 1.

```

Insurance
.find()
.populate({
path: 'production',
match: {status:1}
}
)
.exec(function (err, insurance) {
if (err) {
console.log(err);
return
}
console.log(insurance);
});

```

But this will just gimme all Insurances with "null" production fields if match is false. But i want to filter them..

Valeri Karpov
@vkarpov15
Feb 11 2016 18:00
@jhyland87 yep should be feasible
@alfredopacino I've been looking at making a curated list of plugins at some point, but really depends on what you're trying to achieve. I don't really know of a good way to build web forms from mongoose models, especially if you rely on refs. I mostly just use schemas for validation on the client: http://mongoosejs.com/docs/browser.html and build the web forms myself
@cparadeise probably good to scold the narwhal :p you can use aggregation framework + $lookup: https://docs.mongodb.org/manual/reference/operator/aggregation/lookup/ , or you can group in memory if your data isn't huge.
Konstantin Baierer
@kba
Feb 11 2016 18:05
I have a problem with the mongoose-datetime plugin: It hooks into update but only if this.op === 'update'. What is the purpose of this.op and why is it 'find' and not 'update' in my code?
Valeri Karpov
@vkarpov15
Feb 11 2016 18:06
@Renader no way to do that atm without the aggregation framework: https://docs.mongodb.org/manual/reference/operator/aggregation/lookup/ . General idea is if you want this lookup to be fast, you should look into putting the productionStatus field in the insurance doc. If you're ok with it being slowish, use aggregation + $lookup
@kba not sure, never seen that before. this.op is to track what the operation is for chaining, so you can do stuff like model.update().where(), etc. Can you show some sample code, and preferably open up an issue on mongoose-timestamp?
Renader
@Renader
Feb 11 2016 18:09
thank you @vkarpov15 ! I'll take a look into this!
Chris Paradeise
@cparadeise
Feb 11 2016 18:12
@vkarpov15 nice thanks, I was already looking up the $lookup docs. I shall defeat the narwhal!
antonioaltamura
@antonioaltamura
Feb 11 2016 20:11
guys I have a terrible doubt about a bad schema design I made: I have 4 type of documents. Some fields are in common, some fields not. But I need a unique resource to query the 4 types together (but also a way to query just 1 type, I can totally add a field "type", no problem with that).
At this time I don't think 4 indipendent schemas are the best choice anymore.
@vkarpov15 with mongoose browser I don't have the access to the schemas defined serverside am I right? I have to copy/paste the schema?