MongoDB安装后,浏览器输入http://localhost:27017/后找不到

文章详细介绍了MongoDB启动时可能遇到的问题,包括命令行路径错误、缺少管理员权限,特别是在Windows10家庭版或教育版中。提供了解决方案,如创建指定的数据库路径,以管理员身份运行CMD,以及通过修改注册表和本地安全策略来确保管理员权限。最终,成功启动MongoDB后,可以通过http://localhost:27017/进行访问。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

正常启动后,浏览器输入:http://localhost:27017/

显示如下界面:

访问失败原因:

  1. 启动MongoDB命令错误

正确启动命令如下:

注:需要在mongodb安装目录下,创建 /data/db文件夹

mongod --dbpath=..\data\db

2、命令正确,但cmd命令提示符启动所在目录,不是MongoDB的bin目录

正确启动目录:

3、命令正确,启动目录也正确,但不是已管理员身份运行cmd命令提示符

管理员权限,入下图所示:

原因:

家庭版、教育版等win10系统,默认启动cmd命令提示符,不是管理员权限

解决方案:

需要将:以管理员批准模式运行所有管理员,双击以将本地安全设置更改为禁用。

注:由于win10家庭版、教育版等系统的限制,会提示找不到gpedit.msc,解决方案如下:

1、修改注册表:win10家庭版找不到gpedit.msc的解决办法 - 番茄系统家园 (nndssk.com)
2、将下面代码保存到文本中,并重命名为cmd.reg。双击,可设置为任意位置打开命令行都是管理员身份
Windows Registry Editor Version 5.00

; Created by: Shawn Brink

; http://www.sevenforums.com

; Tutorial: http://www.sevenforums.com/tutorials/47415-open-command-window-here-administrator.html

[-HKEY_CLASSES_ROOT\Directory\shell\runas]

[HKEY_CLASSES_ROOT\Directory\shell\runas]

@="Open cmd here as Admin"

"HasLUAShield"=""

[HKEY_CLASSES_ROOT\Directory\shell\runas\command]

@="cmd.exe /s /k pushd \"%V\""

[-HKEY_CLASSES_ROOT\Directory\Background\shell\runas]

[HKEY_CLASSES_ROOT\Directory\Background\shell\runas]

@="Open cmd here as Admin"

"HasLUAShield"=""

[HKEY_CLASSES_ROOT\Directory\Background\shell\runas\command]

@="cmd.exe /s /k pushd \"%V\""

[-HKEY_CLASSES_ROOT\Drive\shell\runas]

[HKEY_CLASSES_ROOT\Drive\shell\runas]

@="Open cmd here as Admin"

"HasLUAShield"=""

[HKEY_CLASSES_ROOT\Drive\shell\runas\command]

@="cmd.exe /s /k pushd \"%V\""
3、修改本地安全策略
3.1、在开始菜单搜索框里输入secpol或本地安全策略或运行secpol.msc,右键单击以管理员身份打开。

win+R输入 secpol.msc

3.2、展开本地策略,选择安全选项,然后在右侧找到用户帐户控制:以管理员批准模式运行所有管理员,双击以将本地安全设置更改为禁用。

最后,重新启动MongoDB:

mongod --dbpath=..\data\db

正常启动后,浏览器输入:http://localhost:27017/

显示如下界面:

我的app.js const Koa = require('koa'); const { koaBody } = require('koa-body'); const connectDB=require('./db/index'); // koa 实例化 const app = new Koa(); connectDB; // 引入 index 路由 const index = require('./routes/index'); // 使用 koa-body 中间件 app.use(koaBody()); // 使用 index 路由 app.use(index.routes()).use(index.allowedMethods()); // 启动服务器 app.listen(3000, () => { console.log('服务已开启'); }); routes/index.js const Router = require('koa-router'); const router = new Router(); // 创建 Router 实例 // 定义路由 router.get('/', async (ctx) => { ctx.body = 'Hello from index route!'; }); // 导出 Router 实例 module.exports = router; db/models/user.js const mongoose =require('mongoose'); const userSchema =new mongoose.Schema({ usename:String, pwd:String, phone:Number, }) const User=mongoose.model('user',userSchema) module.exports={ User } db/index.js const mongoose =require('mongoose'); module.exports=()=>{ mongoose.connect('mongodb://localhost:27017/users',{ useNewUrlParser: true, useUnifiedTopology: true }) .then(()=>{ console.log('数据库连接成功') }).catch(err =>{ console.log('数据库连接失败',err) }) } 我现在mongoDB显示正常 C:\WINDOWS\system32>net start mongoDB 请求的服务已经启动。Current Mongosh Log ID: 67ecd170fe06171996b71235 Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.4.2 Using MongoDB: 8.0.6 Using Mongosh: 2.4.2
最新发布
04-05
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值