Node.js Mongoose不创建MongoDB,即使以前工作过

Node.js Mongoose不创建MongoDB,即使以前工作过,node.js,mongodb,mongoose,Node.js,Mongodb,Mongoose,我在我的几个项目中使用过Mongoose,但这次我尝试使用Mongoose创建数据库时,它没有共享错误,但不会创建预期的“用户”数据库 例如, const mongoose = require('mongoose'); mongoose.connect('mongodb://localhost:27017/users', {useNewUrlParser: true, useUnifiedTopology: true}) .then(()=>{

我在我的几个项目中使用过Mongoose,但这次我尝试使用Mongoose创建数据库时,它没有共享错误,但不会创建预期的“用户”数据库

例如,

    const mongoose = require('mongoose');
        mongoose.connect('mongodb://localhost:27017/users', {useNewUrlParser: true, useUnifiedTopology: true})
  .then(()=>{
        console.log("mongoose");
    })
    .catch(e=>{
        console.log(e);
    });
此外,我尝试使用以前的数据库创建以前的模型,并尝试使用以前的工作nodejs文件创建新的DBs,但没有成功


如果有人遇到过类似问题或有任何帮助来解决此问题,非常感谢。

我认为问题在于您在配置中忘记了两件事

  • 您忘记了:useCreateIndex:true
  • UseFindModify:false
  • 最后的代码应该是这样的:

    const mongoose = require('mongoose');
    
    
    const dbConnection = async() => {
    
        try {
            
            await mongoose.connect( YourConnectionLink, {
                useNewUrlParser: true,
                useUnifiedTopology: true,
                useCreateIndex: true,
                useFindAndModify: false
            });
    
            console.log('Database online!!');
    
        } catch (error) {
            
            console.log(error);
            throw new Error('Error');
    
        }
    }
    

    在插入文档、创建索引或显式调用
    create
    database命令之前,MongoDB不会创建数据库或集合。

    ,我认为这可能是MongoDB的问题,因为我以前用于连接/创建新DBs的代码样板到目前为止一直有效。可能是Mongo Altas中的网络配置有问题,您是否允许从任何ip访问?