These are chat archives for Automattic/mongoose

Sep 2018
Joe Early
Sep 02 2018 00:31
got her sussed :)
Sep 02 2018 11:36
ZehN Hi all, how do I order a agreegate $lookup array result by date? (the date field is at the "from" document)
Sep 02 2018 11:37
@matrixbot I put a link to a gist above that does this
Zachary Gibson
Sep 02 2018 20:38
Anyone know how to substring a field?
e.g. getting zipcode out of an address field:
Warehouse.find({}, "address") // -> "123 Cool Street, Sacramento, CA, 95814"
Sep 02 2018 22:55
@zachgibson find returns an array with 0 - n length depending on the number of matches. here's a contrived example of a couple ways you could do it
For me, the determining factor for which to use would be how the address string is generated, and what constraints are in place to guarantee the format of the input string.
Zachary Gibson
Sep 02 2018 23:00
@lineus my address string format is always the same, so I just need the last 5 chars in the string
I’m curious just how to do this in general, been researching a bit and looking at the docs and not really finding anything
Sep 02 2018 23:14
if you want to exactly extract the last five characters of the string you could change the instance method to
schema.methods.getZip = function() {
  let start = this.address.length - 5;
  return this.address.slice(start);
since the field is declared as a string in the schema, all of the string.prototype methods are available docs here