Mongodb 7.0.4Windows 版本二进制文件安装

Mongodb 7.0.4Windows 版本二进制文件安装

下载安装包和mongo shell

https://www.mongodb.com/try/download/shell

https://www.mongodb.com/try/download/community

1、解压

2、创建相关目录

data logs conf

3、增加配置文件

复制代码
storage:
    dbPath: "D:\\mongodb-win32-x86_64-windows-7.0.4\\data"
systemLog:
    destination: "file"
    path: "D:\\mongodb-win32-x86_64-windows-7.0.4\\logs\\mongodb.log"
net:
  port: 27017

4、创建并启动服务

复制代码
D:\mongodb-win32-x86_64-windows-7.0.4\bin>mongod --config "D:\mongodb-win32-x86_64-windows-7.0.4\conf\mongodb.cfg" --serviceName MongoDB --serviceDisplayName MongoDB --install

D:\mongodb-win32-x86_64-windows-7.0.4\bin>services.msc

D:\mongodb-win32-x86_64-windows-7.0.4\bin>net start mongodb
MongoDB 服务正在启动 .
MongoDB 服务已经启动成功。

5、查看版本号

复制代码
D:\mongodb-win32-x86_64-windows-7.0.4\bin>mongod.exe --version
db version v7.0.4
Build Info: {
    "version": "7.0.4",
    "gitVersion": "38f3e37057a43d2e9f41a39142681a76062d582e",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distmod": "windows",
        "distarch": "x86_64",
        "target_arch": "x86_64"
    }
}

D:\mongodb-win32-x86_64-windows-7.0.4\bin>

6、mongo shell登陆验证

复制代码
D:\mongosh-2.6.0-win32-x64\bin>mongosh.exe
Current Mongosh Log ID: 6989f0f081e7dcf372628c9f
Connecting to:          mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.6.0
Using MongoDB:          7.0.4
Using Mongosh:          2.6.0

For mongosh info see: https://www.mongodb.com/docs/mongodb-shell/


To help improve our products, anonymous usage data is collected and sent to MongoDB periodically (https://www.mongodb.com/legal/privacy-policy).
You can opt-out by running the disableTelemetry() command.

------
   The server generated these startup warnings when booting
   2026-02-09T22:20:12.844+08:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
   2026-02-09T22:20:12.844+08:00: This server is bound to localhost. Remote systems will be unable to connect to this server. Start the server with --bind_ip <address> to specify which IP addresses it should serve responses from, or with --bind_ip_all to bind to all interfaces. If this behavior is desired, start the server with --bind_ip 127.0.0.1 to disable this warning
------

test>

7、创建管理员账号

创建管理员账号

复制代码
test> use admin
switched to db admin
admin> db.createUser({user: "sysadmin",pwd: "123456",roles: [ { role: "root", db: "admin" } ] })
{ ok: 1 }
admin>

8、修改数据库参数启用密码验证

增加如下参数:

security:

authorization: enabled

复制代码
storage:
    dbPath: "D:\\mongodb-win32-x86_64-windows-7.0.4\\data"
systemLog:
    destination: "file"
    path: "D:\\mongodb-win32-x86_64-windows-7.0.4\\logs\\mongodb.log"
net:
  port: 27017
security:
  authorization: enabled

服务器本地登陆可以直接使用mongosh.exe执行

复制代码
D:\mongosh-2.6.0-win32-x64\bin>mongosh.exe
Current Mongosh Log ID: 6989f2d93601236550628c9f
Connecting to:          mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.6.0
Using MongoDB:          7.0.4
Using Mongosh:          2.6.0

For mongosh info see: https://www.mongodb.com/docs/mongodb-shell/

test>

或者是通过如下命令指定参数登陆

mongosh "mongodb://ip:port"

mongosh ip:port/数据库 -u 用户名 -p 密码

mongosh -u 用户名 -p 密码 --port 端口号 --host ip 数据库名

复制代码
D:\mongosh-2.6.0-win32-x64\bin>mongosh mongodb://127.0.0.1:27017/admin
Current Mongosh Log ID: 6989f3eaf782bf7b9a628c9f
Connecting to:          mongodb://127.0.0.1:27017/admin?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.6.0
Using MongoDB:          7.0.4
Using Mongosh:          2.6.0

For mongosh info see: https://www.mongodb.com/docs/mongodb-shell/

admin>

admin>

D:\mongosh-2.6.0-win32-x64\bin>mongosh mongodb://127.0.0.1:27017/admin -u sysadmin -p
Enter password: ******
Current Mongosh Log ID: 6989f41a8f9e4645f0628c9f
Connecting to:          mongodb://<credentials>@127.0.0.1:27017/admin?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.6.0
Using MongoDB:          7.0.4
Using Mongosh:          2.6.0

For mongosh info see: https://www.mongodb.com/docs/mongodb-shell/

------
   The server generated these startup warnings when booting
   2026-02-09T22:42:46.476+08:00: This server is bound to localhost. Remote systems will be unable to connect to this server. Start the server with --bind_ip <address> to specify which IP addresses it should serve responses from, or with --bind_ip_all to bind to all interfaces. If this behavior is desired, start the server with --bind_ip 127.0.0.1 to disable this warning
------

admin>

登陆数据库提示如下告警,处理方法是在配置文件中增加绑定地址

复制代码
------
   The server generated these startup warnings when booting
   2026-02-09T22:42:46.476+08:00: This server is bound to localhost. Remote systems will be unable to connect to this server. Start the server with --bind_ip <address> to specify which IP addresses it should serve responses from, or with --bind_ip_all to bind to all interfaces. If this behavior is desired, start the server with --bind_ip 127.0.0.1 to disable this warning
------

增加如下配置,重启数据库再次登陆不会再提示。

复制代码
storage:
    dbPath: "D:\\mongodb-win32-x86_64-windows-7.0.4\\data"
systemLog:
    destination: "file"
    path: "D:\\mongodb-win32-x86_64-windows-7.0.4\\logs\\mongodb.log"
net:
  bindIp: 0.0.0.0
  port: 27017
security:
  authorization: enabled

测试创建数据库创建集合和文档

常用命令:

show dbs # 查看所有的数据库

use demodb # 创建demodb数据库

db # 查看当前数据库

db.user.insert({name: "Chaitanya", age: 30}) # 创建user集合并插入一条记录

db.user.find() #查看user集合

#插入多个记录

var beginners =

[

{

"StudentId" : 1001,

"StudentName" : "Steve",

"age": 30

},

{

"StudentId" : 1002,

"StudentName" : "Negan",

"age": 42

},

{

"StudentId" : 3333,

"StudentName" : "Rick",

"age": 35

},

];

db.students.insert(beginners);

示例:

复制代码
admin> use demodb
switched to db demodb
demodb> show dbs
admin   132.00 KiB
config  108.00 KiB
local    72.00 KiB
demodb>

demodb> db.user.insert({name: "Chaitanya", age: 30})
DeprecationWarning: Collection.insert() is deprecated. Use insertOne, insertMany, or bulkWrite.
{
  acknowledged: true,
  insertedIds: { '0': ObjectId('6989f6468b0747a5a4628ca0') }
}
demodb> show dbs
admin   132.00 KiB
config  108.00 KiB
demodb    8.00 KiB
local    72.00 KiB
demodb> db.collection_name.find()

demodb> db.user.find()
[
  {
    _id: ObjectId('6989f6468b0747a5a4628ca0'),
    name: 'Chaitanya',
    age: 30
  }
]
demodb> var beginners =
...  [
...     {
...     "StudentId" : 1001,
...     "StudentName" : "Steve",
...         "age": 30
...     },
...     {
...     "StudentId" : 1002,
...     "StudentName" : "Negan",
...         "age": 42
...     },
...     {
...     "StudentId" : 3333,
...     "StudentName" : "Rick",
...         "age": 35
...     },
... ];

demodb> db.students.insert(beginners);
{
  acknowledged: true,
  insertedIds: {
    '0': ObjectId('6989f7798b0747a5a4628ca1'),
    '1': ObjectId('6989f7798b0747a5a4628ca2'),
    '2': ObjectId('6989f7798b0747a5a4628ca3')
  }
}
demodb> db.students.find()
[
  {
    _id: ObjectId('6989f7798b0747a5a4628ca1'),
    StudentId: 1001,
    StudentName: 'Steve',
    age: 30
  },
  {
    _id: ObjectId('6989f7798b0747a5a4628ca2'),
    StudentId: 1002,
    StudentName: 'Negan',
    age: 42
  },
  {
    _id: ObjectId('6989f7798b0747a5a4628ca3'),
    StudentId: 3333,
    StudentName: 'Rick',
    age: 35
  }
]
demodb>
相关推荐
冬奇Lab21 小时前
每日一个开源项目(第134篇):Zvec - 阿里开源的嵌入式向量数据库,向量搜索界的 SQLite
数据库·人工智能·llm
ClouGence1 天前
Oracle CDC 架构优化:从主库直连到 DataGuard 备库同步
数据库·后端·oracle
无响应de神1 天前
三、用户与权限管理
数据库·mysql
✎ ﹏梦醒͜ღ҉繁华落℘2 天前
单片机基础知识---stm32单片机的优先级
stm32·单片机·mongodb
麦聪聊数据2 天前
数据服务化时代:企业数据能力输出的核心路径
数据库
shushangyun_2 天前
2026年快消品B2B系统推荐:支持终端门店订货、促销政策自动化的工具?
java·运维·网络·数据库·人工智能·spring·自动化
DARLING Zero two♡2 天前
【MySQL数据库】数据类型与表约束
数据库·mysql
曹牧2 天前
Oracle EXPLAIN PLAN
数据库·oracle
BD_Marathon2 天前
SQL学习指南——视图
数据库·sql
活宝小娜2 天前
mysql详细安装教程
数据库·mysql·adb