T
T
TipoImya2020-08-13 10:43:33
MongoDB
TipoImya, 2020-08-13 10:43:33

MongoDB creates a database I don't need. Why?

I have a command and a "rusters" database, if a person registers it, then first there is a request to the database, if this person is in the database, then everything is OK - we execute the command further, if not, then we create a document in the database in the collection " users" and enter some data about this user there, for example, the id of the author of the message.
This is what I did. Everything worked fine, but at some point I decided to add another collection, let's say moderators and, accordingly, another command. But instead of writing to the "rusters" database, the "moderators" collection, a database is created with the name "dbname" with the "moderators" collection and a document is created there, but the old database is there, and it has not gone away. With what it can be connected and how to solve it? my task is to write to the collection "

let User = require('./data/user.js');
bot.on("message", message => {
  if(message.content.startsWith("!test")) {
    User.findOne({userID: message.author.id}, (err, Data) => {
      if(err) console.log(err);
      if(!Data) { // если нету пароля с таким названием.
        let NewData = new User({ userID: message.author.id, coins: 0});
        return NewData.save().catch(err => message.channel.send(`\`[⚠️ DataBase]\` Произошла ошибка во время сохранения данных. Ошибка: ${err}`))
      }
      message.delete()
      let embed = new Discord.MessageEmbed()
      .setTitle('Ошибка!')
      .setColor("RED")
      .setDescription(`Такой пользователь уже есть!`)
      .setThumbnail('http://i.yapx.ru/IfkAN.png')
      return message.channel.send(embed)
      .then(msg => msg.delete({timeout: 10000}))
    })
  }
})


Content in user.js.

const mongoose = require('mongoose');
const schema = mongoose.Schema({
    userID: String,
    coins: { type: Number, default: 0 },
});
module.exports = mongoose.model("User", schema)

this is what is being created

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Saboteur, 2020-08-13
@saboteur_kiev

And where in your connection to mongodb is the choice of base?
Either run use rusterscluster before the request, or you should specify the default base in the connection settings.
I suspect that you have db=dbname directly in your settings, as it was in some example.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question