const mongoose = require('mongoose'); let inventorySchema = mongoose.Schema({ inventory: { userID: String, guilds: {}, } }); inventorySchema.methods.createInventory = function (userID, guildID) { this.inventory.userID = userID; const newGuild = { items: [{ name: 'Wallet', type: 'wallet', description: '`/wallet view` to view wallet', cash: 0.00, ID: { firstname: '', lastname: '', dob: '' } }], lastWork: new Date('2000-01-01T00:00:00') // garantee's they can work right after inventory create, }; this.inventory.guilds[guildID] = newGuild }; inventorySchema.methods.addItem = function (guildID, item) { this.inventory.guilds[guildID].items.push(item); }; // This function is to add a new guild specific inventory to an already existing // inventory document function addInventory(guilds, guildID, userID, client) { let updatedGuilds = guilds; updatedGuilds[guildID] = { items: [{ name: 'Wallet', type: 'wallet', description: '`/wallet view` to view wallet', cash: 0.00, ID: { firstname: '', lastname: '', dob: '' } }], } client.dbo.collection("inventories").updateOne({"inventory.userID":userID}, {$set: {"inventory.guilds": updatedGuilds}}, function(err, res) { if (err) return false }) return true } module.exports = { Inventory: mongoose.model('Inventory', inventorySchema), addInventory: addInventory, };