I have an issue with my model where I am attempting to push an array to an empty array, but for some reason the changes are not reflected in Compass.
Various approaches were tried to remedy this situation such as setting the type of user_list
property to array
and initializing it as an empty array using []
. Additionally, deleting and recreating the entire database was done to rule out any memory-related problems.
Model:
const guildSchema = new Schema({
guild_name: String,
guild_id: { type: String, unique: true },
...
user_list: []
})
Fetching the array and attempting to push:
bot.on("guildUpdate", (oldGuild, newGuild) => {
let userList = newGuild.fetchMembers().then(function(results){ console.log(results.members.keyArray()); userList = results.members.keyArray();
Guild.findOneAndUpdate({guild_id: oldGuild.id}, {"$set": {"guild_name": newGuild.name, "guild_icon": newGuild.iconURL}}, {"$push": {"user_list": userList}}, function(err) {
if (err) throw (err);
});
}).catch(console.error)
})
console.log(results.members.keyArray())
displays the desired array without any issues. Furthermore, updates made using $set
are visible in Compass. However, the problem lies specifically in pushing to user_list
, as Compass fails to reflect these changes and continues to display a blank array post-update.