These are chat archives for Automattic/mongoose

27th
Feb 2018
Kev
@lineus
Feb 27 2018 12:58
@hillct did you find the answer to your question?
hillct
@hillct
Feb 27 2018 14:45
Kev: not yet
Kev
@lineus
Feb 27 2018 15:16
because the reference is just a pointer to a specific document within a collection, and gets cast and validated by mongoose, I don't think you'll be able to attach any other properties to the reference itself. You'd probably want to add a path to either the referenced document or within the document where the reference is stored. I'll test it out and see though.
@hillct ^
hillct
@hillct
Feb 27 2018 15:23
@lineus that makes sense but do I need a subschema/document to represent a single instance/array item where I'll have an array of these referential objects including other metadata for each reference? Or can I do all that within my primary document schema?
Kev
@lineus
Feb 27 2018 15:33
in order for mongoose to associate the document id with the collection in the reference, you'll need to have a model for both collections, and so a schema for both. for example
keeping in mind, I'm not any kind of an authority. mostly I just say things and hope that more experienced folks will correct me when I'm wrong.
usually when I say something though, I have either tried to verify it with an example or I am about to.
hillct
@hillct
Feb 27 2018 17:33
@lineus I understand that the source and referenced documents most each have models. My question here - to clarify - is whether a third model would be needed to represent objects which would exist only as array elements in a source document, but where each array element / object would itself consist in part of a reference to a document within a target collection
Kev
@lineus
Feb 27 2018 18:24
sorry for misunderstanding. no, a model wouldn't be needed for sub-documents.
Osny Netto
@osnysantos
Feb 27 2018 19:04
Hello guys, Im using this aggregate but its taking about 4s to respond. Can someone help me to decrease this number?
let aggregate = [
        {
          $match: {
            'object._id': e._id.toString(),
            'object.flow': flowId,
            status: 'start',
            type: 'step',
            view: {$exists: true},
            'createdAt': {
              $gte: startDate.startOf('day').toDate(),
              $lte: endDate.endOf('day').toDate()
            }
          }
        },
        {
          $group: {
            _id: '$user.alias',
            total: { $sum : 1 }
          }
        },
        {
          explain:true
        }
      ]