'Mongoose findOne() not returning entire document
So I have this Schema
const playerCharacter = new Schema({
userID: String,
guildID: String,
username: String,
characterName: String,
characterImgUrl: String,
hp: [Number, Number],
humanity: [Number, Number],
role: String,
abilities: [{ name: String, rank: Number }],
criticalInjuries: [String],
addictions: [String],
eb: Number,
ip: Number,
stats: {
...
},
skills: {
...
},
armor: {
...
},
weapons: [
{
ref: String,
name: String,
ammo: Number,
magSize: String,
ammoLoaded: String,
rangeDV: [Number],
dmg: String,
standardMag: Number,
extendedMg: Number,
drumMag: Number,
rof: Number,
hands: Number,
isAutofire: Boolean,
afMultiplier: Number,
suppressiveFire: Boolean,
skillRef: String,
skillName: String,
ammoType: String,
cost: Number,
},
],
ammo: [{ ref: String, name: String, type: String, amount: Number }],
cyberwear: [{ ref: String, name: String, desc: String }],
inventory: [{ ref: String, name: String, amount: Number }],
});
And I use this query:
const pc = await Character.findOne({
userID: `${interaction.member.id}`,
});
The console.log(pc) returns the document correctly until here...
}
],
cyberwear: [
{ ref: 'neural_link', name: 'Neural Link', desc: ' ' },
{ ref: 'cyber_deck', name: 'Cyberdeck', desc: ' ' }
],
inventory: [],
__v: 1
}
If I delete the nested object in the Schema to get ammo: [{}] or use .lean() the document returns correctly. I would use .lean() to get the document correctly, or delete the object schema if I didn't need to change the values and .save().
Considering that I use very similar definitions for "cyberwear", it seems strange the the "ammo" definition is behaving this way.
Solution 1:[1]
TLDR: It didn't show the "ammo" array of objects because one of the key-value pairs used the name "type". I feel like a dumb.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Adam Cope |
