目录
Create and Alter
Insert
Select
Update Records
Delete Records
首页 数据库 mysql教程 mongodb安装笔记【服务没有及时响应或控制请求】

mongodb安装笔记【服务没有及时响应或控制请求】

Jun 07, 2016 pm 03:28 PM
mongodb 响应 安装 控制 服务 笔记

mongodb安装笔记 --下面大部分都是参考网上资料,仅仅作为笔记使用 参考链接 Mongodb官网安装 Mongodb官网对比 相关文档 我的mongodb安装在[d:\Java\mongodb] 所以需要根目录手动创建文件夹【e:\data\db】 mongodb使用服务方式安装 D:\Java\mongodb\bin\mong

mongodb安装笔记

--下面大部分都是参考网上资料,仅仅作为笔记使用

参考链接

Mongodb官网安装

Mongodb官网对比

相关文档

我的mongodb安装在[d:\Java\mongodb]

所以需要根目录手动创建文件夹【e:\data\db】

mongodb使用服务方式安装

1

2

3

4

'D:\Java\mongodb\bin\mongod.exe --bind_ip 127.0.0.1 --logpath d:\\Java\\mongodb

\\logs\\MongoLog.log --logappend --dbpath d:\\data --directoryperdb --service'

Fri Jan 10 09:17:45.050 Service can be started from the command line with 'net s

tart MongoDB'

登录后复制
日志需要指定具体的文件,比如MongoLog.log 之前没有置顶就报错【服务没有及时响应或控制请求】

安装、删除服务指令

mongod --install

mongod --service

mongod --remove

mongod --reinstall

或者

1

C:\mongodb\bin\mongod.exe --remove

登录后复制

启动服务

1

net start Mongodb

登录后复制
停止服务

1

net stop Mongodb

登录后复制
测试简单JavaScript语句

1

2

3

4

5

6

7

8

9

10

11

> 3+3

6

 

> db

test

> // the first write will create the db:

 

> db.foo.insert( { a : 1 } )

> db.foo.find()

{ _id : ..., a : 1 }

mongo.exe的详细的用法可以参考mongo.exe --help

登录后复制

下面从官网摘抄下来的普通sql跟MongoDB的区别

Create and Alter

The following table presents the various SQL statements related totable-level actions and the corresponding MongoDB statements.

SQL Schema Statements MongoDB Schema Statements Reference

1

2

3

4

5

6

7

8

CREATE TABLE users (

    id MEDIUMINT NOT NULL

        AUTO_INCREMENT,

    user_id Varchar(30),

    age Number,

    status char(1),

    PRIMARY KEY (id)

)

登录后复制

Implicitly created on first insert() operation. The primary key_idis automatically added if_id field is not specified.

1

2

3

4

5

db.users.insert( {

    user_id: "abc123",

    age: 55,

    status: "A"

 } )

登录后复制

However, you can also explicitly create a collection:

1

db.createCollection("users")

登录后复制
Seeinsert() anddb.createCollection()for more information.

1

2

ALTER TABLE users

ADD join_date DATETIME

登录后复制

Collections do not describe or enforce the structure of itsdocuments; i.e. there is no structural alteration at thecollection level.

However, at the document level, update() operations can add fields to existingdocuments using the$set operator.

1

2

3

4

5

db.users.update(

    { },

    { $set: { join_date: new Date() } },

    { multi: true }

)

登录后复制
See the Data Modeling Concepts, update(), and$set for moreinformation on changing the structure of documents in acollection.

1

2

ALTER TABLE users

DROP COLUMN join_date

登录后复制

Collections do not describe or enforce the structure of itsdocuments; i.e. there is no structural alteration at the collectionlevel.

However, at the document level, update() operations can remove fields fromdocuments using the$unset operator.

1

2

3

4

5

db.users.update(

    { },

    { $unset: { join_date: "" } },

    { multi: true }

)

登录后复制
See Data Modeling Concepts, update(), and$unset for more information on changing the structure ofdocuments in a collection.

1

2

CREATE INDEX idx_user_id_asc

ON users(user_id)

登录后复制

1

db.users.ensureIndex( { user_id: 1 } )

登录后复制
See ensureIndex()andindexes for more information.

1

2

3

CREATE INDEX

       idx_user_id_asc_age_desc

ON users(user_id, age DESC)

登录后复制

1

db.users.ensureIndex( { user_id: 1, age: -1 } )

登录后复制
See ensureIndex()andindexes for more information.

1

DROP TABLE users

登录后复制

1

db.users.drop()

登录后复制
See drop() formore information.

Insert

The following table presents the various SQL statements related toinserting records into tables and the corresponding MongoDB statements.

SQL INSERT Statements MongoDB insert() Statements Reference

1

2

3

4

5

6

INSERT INTO users(user_id,

                  age,

                  status)

VALUES ("bcd001",

        45,

        "A")

登录后复制

1

2

3

4

5

db.users.insert( {

       user_id: "bcd001",

       age: 45,

       status: "A"

} )

登录后复制
See insert() for more information.

Select

The following table presents the various SQL statements related toreading records from tables and the corresponding MongoDB statements.

SQL SELECT Statements MongoDB find() Statements Reference

1

2

SELECT *

FROM users

登录后复制

1

db.users.find()

登录后复制
See find()for more information.

1

2

SELECT id, user_id, status

FROM users

登录后复制

1

2

3

4

db.users.find(

    { },

    { user_id: 1, status: 1 }

)

登录后复制
See find()for more information.

1

2

SELECT user_id, status

FROM users

登录后复制

1

2

3

4

db.users.find(

    { },

    { user_id: 1, status: 1, _id: 0 }

)

登录后复制
See find()for more information.

1

2

3

SELECT *

FROM users

WHERE status = "A"

登录后复制

1

2

3

db.users.find(

    { status: "A" }

)

登录后复制
See find()for more information.

1

2

3

SELECT user_id, status

FROM users

WHERE status = "A"

登录后复制

1

2

3

4

db.users.find(

    { status: "A" },

    { user_id: 1, status: 1, _id: 0 }

)

登录后复制
See find()for more information.

1

2

3

SELECT *

FROM users

WHERE status != "A"

登录后复制

1

2

3

db.users.find(

    { status: { $ne: "A" } }

)

登录后复制
See find()and$ne for more information.

1

2

3

4

SELECT *

FROM users

WHERE status = "A"

AND age = 50

登录后复制

1

2

3

4

db.users.find(

    { status: "A",

      age: 50 }

)

登录后复制
See find()and$and for more information.

1

2

3

4

SELECT *

FROM users

WHERE status = "A"

OR age = 50

登录后复制

1

2

3

4

db.users.find(

    { $or: [ { status: "A" } ,

             { age: 50 } ] }

)

登录后复制
See find()and$or for more information.

1

2

3

SELECT *

FROM users

WHERE age > 25

登录后复制

1

2

3

db.users.find(

    { age: { $gt: 25 } }

)

登录后复制
See find()and$gt for more information.

1

2

3

SELECT *

FROM users

WHERE age < 25

登录后复制

1

2

3

db.users.find(

   { age: { $lt: 25 } }

)

登录后复制
See find()and$lt for more information.

1

2

3

4

SELECT *

FROM users

WHERE age > 25

AND   age <= 50

登录后复制

1

2

3

db.users.find(

   { age: { $gt: 25, $lte: 50 } }

)

登录后复制
See find(),$gt, and $lte formore information.

1

2

3

SELECT *

FROM users

WHERE user_id like "%bc%"

登录后复制

1

2

3

db.users.find(

   { user_id: /bc/ }

)

登录后复制
See find()and$regex for more information.

1

2

3

SELECT *

FROM users

WHERE user_id like "bc%"

登录后复制

1

2

3

db.users.find(

   { user_id: /^bc/ }

)

登录后复制
See find()and$regex for more information.

1

2

3

4

SELECT *

FROM users

WHERE status = "A"

ORDER BY user_id ASC

登录后复制

1

db.users.find( { status: "A" } ).sort( { user_id: 1 } )

登录后复制
See find()andsort()for more information.

1

2

3

4

SELECT *

FROM users

WHERE status = "A"

ORDER BY user_id DESC

登录后复制

1

db.users.find( { status: "A" } ).sort( { user_id: -1 } )

登录后复制
See find()andsort()for more information.

1

2

SELECT COUNT(*)

FROM users

登录后复制

1

db.users.count()

登录后复制

or

1

db.users.find().count()

登录后复制
See find()andcount() formore information.

1

2

SELECT COUNT(user_id)

FROM users

登录后复制

1

db.users.count( { user_id: { $exists: true } } )

登录后复制

or

1

db.users.find( { user_id: { $exists: true } } ).count()

登录后复制
See find(),count(), and$exists for more information.

1

2

3

SELECT COUNT(*)

FROM users

WHERE age > 30

登录后复制

1

db.users.count( { age: { $gt: 30 } } )

登录后复制

or

1

db.users.find( { age: { $gt: 30 } } ).count()

登录后复制
See find(),count(), and$gt for more information.

1

2

SELECT DISTINCT(status)

FROM users

登录后复制

1

db.users.distinct( "status" )

登录后复制
See find()anddistinct()for more information.

1

2

3

SELECT *

FROM users

LIMIT 1

登录后复制

1

db.users.findOne()

登录后复制

or

1

db.users.find().limit(1)

登录后复制
See find(),findOne(),andlimit()for more information.

1

2

3

4

SELECT *

FROM users

LIMIT 5

SKIP 10

登录后复制

1

db.users.find().limit(5).skip(10)

登录后复制
See find(),limit(), andskip() formore information.

1

2

3

EXPLAIN SELECT *

FROM users

WHERE status = "A"

登录后复制

1

db.users.find( { status: "A" } ).explain()

登录后复制
See find()andexplain()for more information.

Update Records

The following table presents the various SQL statements related toupdating existing records in tables and the corresponding MongoDBstatements.

SQL Update Statements MongoDB update() Statements Reference

1

2

3

UPDATE users

SET status = "C"

WHERE age > 25

登录后复制

1

2

3

4

5

db.users.update(

   { age: { $gt: 25 } },

   { $set: { status: "C" } },

   { multi: true }

)

登录后复制
See update(),$gt, and $set for moreinformation.

1

2

3

UPDATE users

SET age = age + 3

WHERE status = "A"

登录后复制

1

2

3

4

5

db.users.update(

   { status: "A" } ,

   { $inc: { age: 3 } },

   { multi: true }

)

登录后复制
See update(),$inc, and $set for moreinformation.

Delete Records

The following table presents the various SQL statements related todeleting records from tables and the corresponding MongoDB statements.

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

<🎜>:泡泡胶模拟器无穷大 - 如何获取和使用皇家钥匙
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
北端:融合系统,解释
4 周前 By 尊渡假赌尊渡假赌尊渡假赌
Mandragora:巫婆树的耳语 - 如何解锁抓钩
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

热门话题

Java教程
1670
14
CakePHP 教程
1428
52
Laravel 教程
1329
25
PHP教程
1274
29
C# 教程
1256
24
使用 Composer 解决推荐系统的困境:andres-montanez/recommendations-bundle 的实践 使用 Composer 解决推荐系统的困境:andres-montanez/recommendations-bundle 的实践 Apr 18, 2025 am 11:48 AM

在开发一个电商网站时,我遇到了一个棘手的问题:如何为用户提供个性化的商品推荐。最初,我尝试了一些简单的推荐算法,但效果并不理想,用户的满意度也因此受到影响。为了提升推荐系统的精度和效率,我决定采用更专业的解决方案。最终,我通过Composer安装了andres-montanez/recommendations-bundle,这不仅解决了我的问题,还大大提升了推荐系统的性能。可以通过一下地址学习composer:学习地址

Navicat查看MongoDB数据库密码的方法 Navicat查看MongoDB数据库密码的方法 Apr 08, 2025 pm 09:39 PM

直接通过 Navicat 查看 MongoDB 密码是不可能的,因为它以哈希值形式存储。取回丢失密码的方法:1. 重置密码;2. 检查配置文件(可能包含哈希值);3. 检查代码(可能硬编码密码)。

CentOS上GitLab的数据库如何选择 CentOS上GitLab的数据库如何选择 Apr 14, 2025 pm 04:48 PM

CentOS系统上GitLab数据库部署指南选择合适的数据库是成功部署GitLab的关键步骤。GitLab兼容多种数据库,包括MySQL、PostgreSQL和MongoDB。本文将详细介绍如何选择并配置这些数据库。数据库选择建议MySQL:一款广泛应用的关系型数据库管理系统(RDBMS),性能稳定,适用于大多数GitLab部署场景。PostgreSQL:功能强大的开源RDBMS,支持复杂查询和高级特性,适合处理大型数据集。MongoDB:流行的NoSQL数据库,擅长处理海

CentOS MongoDB备份策略是什么 CentOS MongoDB备份策略是什么 Apr 14, 2025 pm 04:51 PM

CentOS系统下MongoDB高效备份策略详解本文将详细介绍在CentOS系统上实施MongoDB备份的多种策略,以确保数据安全和业务连续性。我们将涵盖手动备份、定时备份、自动化脚本备份以及Docker容器环境下的备份方法,并提供备份文件管理的最佳实践。手动备份:利用mongodump命令进行手动全量备份,例如:mongodump-hlocalhost:27017-u用户名-p密码-d数据库名称-o/备份目录此命令会将指定数据库的数据及元数据导出到指定的备份目录。

MongoDB 与关系数据库:全面比较 MongoDB 与关系数据库:全面比较 Apr 08, 2025 pm 06:30 PM

MongoDB与关系型数据库:深度对比本文将深入探讨NoSQL数据库MongoDB与传统关系型数据库(如MySQL和SQLServer)的差异。关系型数据库采用行和列的表格结构组织数据,而MongoDB则使用灵活的面向文档模型,更适应现代应用的需求。主要区别数据结构:关系型数据库使用预定义模式的表格存储数据,表间关系通过主键和外键建立;MongoDB使用类似JSON的BSON文档存储在集合中,每个文档结构可独立变化,实现无模式设计。架构设计:关系型数据库需要预先定义固定的模式;MongoDB支持

mongodb怎么设置用户 mongodb怎么设置用户 Apr 12, 2025 am 08:51 AM

要设置 MongoDB 用户,请按照以下步骤操作:1. 连接到服务器并创建管理员用户。2. 创建要授予用户访问权限的数据库。3. 使用 createUser 命令创建用户并指定其角色和数据库访问权限。4. 使用 getUsers 命令检查创建的用户。5. 可选地设置其他权限或授予用户对特定集合的权限。

Debian MongoDB如何进行数据加密 Debian MongoDB如何进行数据加密 Apr 12, 2025 pm 08:03 PM

在Debian系统上为MongoDB数据库加密,需要遵循以下步骤:第一步:安装MongoDB首先,确保您的Debian系统已安装MongoDB。如果没有,请参考MongoDB官方文档进行安装:https://docs.mongodb.com/manual/tutorial/install-mongodb-on-debian/第二步:生成加密密钥文件创建一个包含加密密钥的文件,并设置正确的权限:ddif=/dev/urandomof=/etc/mongodb-keyfilebs=512

连接mongodb的工具有哪些 连接mongodb的工具有哪些 Apr 12, 2025 am 06:51 AM

连接MongoDB的工具主要有:1. MongoDB Shell,适用于快速查看数据和执行简单操作;2. 编程语言驱动程序(如PyMongo, MongoDB Java Driver, MongoDB Node.js Driver),适合应用开发,但需掌握其使用方法;3. GUI工具(如Robo 3T, Compass),提供图形化界面,方便初学者和快速数据查看。选择工具需考虑应用场景和技术栈,并注意连接字符串配置、权限管理及性能优化,如使用连接池和索引。

See all articles
SQL Delete Statements MongoDB remove() Statements Reference

1

2

DELETE FROM users

WHERE status = "D"

登录后复制

1

db.users.remove( { status: "D" } )

登录后复制
See remove()for more information.

1

DELETE FROM users

登录后复制

1

db.users.remove( )

登录后复制
See remove()for more information.