node.jsmongodbmongoosediscord.js

db.collection.insertOne not working, is there something wrong with my code?


Ok, so here's some context. Basically, I'm making a Discord bot and I'm using Mongoose to store user data, like how much gold they have in their bank, but I've tried looking at tutorials and copying code (we're all guilty of it) but nothing seems to work. Here's my code:

const user = db.collection.insertOne({
    _id: mongoose.Types.ObjectId,
    guild: msg.guild.id,
    gold: 0,
})

Solution

  • with mongodb command

    db.collection.insert({...})
    

    You can check it out here

    OR

    with mongoose

    myModel.create({...})
    

    You can check it out here