Problem with mongodb, findOne() returning null

Hey @HK420 I think the issue is your query over the array ‘characters’. The Mongo docs say that your query characters : [{CharacterID: CharID}] will be interpreted literally, the elements in the document including their order must match your query, you’re getting null because your document has > 1 elements and the elements are also not the same shape, i think. It might be easier to achieve what you want to do by filtering the result of the following query in your callback:

{
    guildID: bot.guilds.cache.get(message.guild.id).id,
    userID: user.id,
}

EDIT: you might find docs on querying embedded documents in arrays helpful, seems like the following might work:

{
    guildID: bot.guilds.cache.get(message.guild.id).id,
    userID: user.id,
    "characters.CharacterID": CharID,
}
1 Like