These are chat archives for Automattic/mongoose

13th
Feb 2019
Max
@maxpaj
Feb 13 15:22
@jeffallen6767 Would it make sense to write a MongoDB script that fixes those errors for the entire database?
Max
@maxpaj
Feb 13 15:31
I'm getting this weird thing today on a codebase I've been maintaining for 2 years+. I can't do querys on a property that is an ObjectId using a string (parsed from an URL or something). Like, User.findById("5982e8c80f30a12f93481854"), returns null. This has been working before. And also, if I query on something else and actually get a result back, the _id field on those objects is undefined. I can see that the _doc._id is actually present, but the _id field is missing. What have I done wrong? I don't recall making any changes to mongoose.
Max
@maxpaj
Feb 13 15:59
Hm. Okay, so explicitly adding _id: { type: Types.ObjectId } to the Schema definition made it work again. Weird.
Karthik Iyengar
@karthikiyengar
Feb 13 19:41
Any idea why @types/mongoose behaves weirdly with TypeScript 3+?
const test = await Promise.all([User.findOne({})])
Argument of type 'DocumentQuery<IUser, IUser, {}>[]' is not assignable to parameter of type 'Iterable<IUser | PromiseLike<IUser>>'.
  Types of property '[Symbol.iterator]' are incompatible.
    Type '() => IterableIterator<DocumentQuery<IUser, IUser, {}>>' is not assignable to type '() => Iterator<IUser | PromiseLike<IUser>>’.
There’s more in the error, but keeping it short
This works perfectly fine with TS2.9 and friends.
Karthik Iyengar
@karthikiyengar
Feb 13 20:34
Dropped an issue for more details: DefinitelyTyped/DefinitelyTyped#33047
hillct
@hillct
Feb 13 21:41
Good afternoon all. I've run into an issue whereby I'm having difficulty updating an array of subdocuments using the typical an expected JS syntax: array.forEach(function(v){ delete v.bad }); Is there a more suitable syntax when performing the same operation using a mongoose document array of subdocuments?