0
return new SavedMember({
    id: member.id, // ID of the user
    guildId: member.guild.id // ID of the guild
}).save();

gives error:

  message: 'Cast to ObjectId failed for value "218459216145285121" at path "_id" for model "member"',    
  name: 'CastError',
  model: Model { member }

member.ts

const memberSchema = new Schema({
    _id: Types.ObjectId,
    id: String,
    guildId: String,
    xpMessages: { type: Number, default: 0 },
    warnings: { type: Array, default: [] }
});
...
export const SavedMember = model<MemberDocument>('member', memberSchema);

Repo: https://github.com/theADAMJR/2pg-dashboard

ADAMJR
  • 1,880
  • 1
  • 14
  • 34

1 Answers1

2

Based on this other answer here:

Mongoose assigns each of your schemas an id virtual getter by default which returns the documents _id field cast to a string, or in the case of ObjectIds, its hexString.

So, when you try to add a new document, the id property refers to _id

Rodrigo
  • 81
  • 1
  • 4