MongooseDocumentArray assignment
I have a MongooseDocumentArray found at this.prices. I can clear it with
this.prices = [] and it retains all of its methods etc. and remains a
MongooseDocumentArray. If I assign it to another variable first, e.g.
array = this.prices, then array is also a MongooseDocuementArray, and
changing one changes the other (i.e. they appear to be the same object).
However, if I then attempt to clear that one with array = [], I find that
array is now a plain, empty JS array. Doing array.length = 0 works fine,
however. Can someone explain to me why this is and also how doing it with
the original object works? I'm guessing this is more of a JS thing than a
specifically Mongoose thing, but either way I'm perplexed.
No comments:
Post a Comment