These are chat archives for Automattic/mongoose

2nd
Jun 2018
Daniel Netzer
@DanielNetzer
Jun 02 2018 05:26
@lineus how would you manage with the _id in populated sub documents?
Kev
@lineus
Jun 02 2018 09:40
@DanielNetzer same thing - gist here
Daniel Netzer
@DanielNetzer
Jun 02 2018 14:13
@lineus but those are documents that you instantiated, I have sub documents that are auto instantiated and still have the _id property instead of id, and I dont even know why mongoose creates them as sub documents
when I create a new Bot using this model, https://gist.github.com/DanielNetzer/9f9cfce6e214b2937da2c38336045c58 some of the more complexed properties auto created as sub documents and have an '_id' field
something like this,
Daniel Netzer
@DanielNetzer
Jun 02 2018 14:19
i:{entities: ["price", "type"], utterances: [{entityLabels: [], _id: "5b10f4e20de72f08f8a30fed",…},…]}
entities:["price", "type"]
utterances:[{entityLabels: [], _id: "5b10f4e20de72f08f8a30fed",…},…]
0:{entityLabels: [], _id: "5b10f4e20de72f08f8a30fed",…}
entityLabels:[]
intentName:"Outfits"
text:"15mm Combo Wrench, This is a demonstration store. You can purchase products like this from Pure Fix Cycles This wrench packs a 10mm open-ended, 15mm pedal wrench & 14x15mm sockets for crank fixing bolts and axle nuts. It's constructed with CrMo steel and is the perfect wrench to keep your wheels and pedals on tight!"
_id:"5b10f4e20de72f08f8a30fed"
each utterance is a sub document, each product is a sub docuemnt and they all have '_id' properties
Kev
@lineus
Jun 02 2018 14:41
@DanielNetzer what do you see when you try to access .id on one of your embedded docs? It should just return the string of _id GIST HERE
Kev
@lineus
Jun 02 2018 15:04
If you're trying to see the id property on the embedded doc ala Object.keys that won't work because it doesn't strictly exist there. It's a virtual getter that's defined in the Schema, even in implicit ones.
Daniel Netzer
@DanielNetzer
Jun 02 2018 15:09
exactly what I thought, and they are auto created, I dont use the NEW for them. mongoose auto creates them which is useful tbh but they dont send the virtuals sadly.
ill just need to break down my API into much more specific requests and creation of data so I can control the instantiation of those sub doc's.
@lineus thank you for the help.
Kev
@lineus
Jun 02 2018 15:11
can you create a stand alone example where the id virtual doesn't exist on the subdoc? the gist i pasted a few comments ago shows that it does.
or modify mine
Daniel Netzer
@DanielNetzer
Jun 02 2018 15:12
ill try to
Kev
@lineus
Jun 02 2018 15:12
cool thanks!
Daniel Netzer
@DanielNetzer
Jun 02 2018 15:13
i'm not really sure where to start such a gist, I can send you the process of creating that Bot object, the model and the get request
anywhere there is [Array]/[Object] any item in that collection will have a '_id' property and wont return the virtuals
Kev
@lineus
Jun 02 2018 15:18
which path is the one without virtuals?
Daniel Netzer
@DanielNetzer
Jun 02 2018 15:21
every object inside ai -> products or settings -> openingMessage -> options
Kev
@lineus
Jun 02 2018 15:26
I don't see settings in your schema
is that from a different one?
Daniel Netzer
@DanielNetzer
Jun 02 2018 15:27
yea