目录
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使用服务方式安装

 '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

或者

C:\mongodb\bin\mongod.exe --remove
登录后复制

启动服务

net start Mongodb
登录后复制
停止服务
net stop Mongodb
登录后复制
测试简单JavaScript语句
> 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
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.

db.users.insert( {
    user_id: "abc123",
    age: 55,
    status: "A"
 } )
登录后复制

However, you can also explicitly create a collection:

db.createCollection("users")
登录后复制
Seeinsert() anddb.createCollection()for more information.
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.

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.
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.

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.
CREATE INDEX idx_user_id_asc
ON users(user_id)
登录后复制
db.users.ensureIndex( { user_id: 1 } )
登录后复制
See ensureIndex()andindexes for more information.
CREATE INDEX
       idx_user_id_asc_age_desc
ON users(user_id, age DESC)
登录后复制
db.users.ensureIndex( { user_id: 1, age: -1 } )
登录后复制
See ensureIndex()andindexes for more information.
DROP TABLE users
登录后复制
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
INSERT INTO users(user_id,
                  age,
                  status)
VALUES ("bcd001",
        45,
        "A")
登录后复制
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
SELECT *
FROM users
登录后复制
db.users.find()
登录后复制
See find()for more information.
SELECT id, user_id, status
FROM users
登录后复制
db.users.find(
    { },
    { user_id: 1, status: 1 }
)
登录后复制
See find()for more information.
SELECT user_id, status
FROM users
登录后复制
db.users.find(
    { },
    { user_id: 1, status: 1, _id: 0 }
)
登录后复制
See find()for more information.
SELECT *
FROM users
WHERE status = "A"
登录后复制
db.users.find(
    { status: "A" }
)
登录后复制
See find()for more information.
SELECT user_id, status
FROM users
WHERE status = "A"
登录后复制
db.users.find(
    { status: "A" },
    { user_id: 1, status: 1, _id: 0 }
)
登录后复制
See find()for more information.
SELECT *
FROM users
WHERE status != "A"
登录后复制
db.users.find(
    { status: { $ne: "A" } }
)
登录后复制
See find()and$ne for more information.
SELECT *
FROM users
WHERE status = "A"
AND age = 50
登录后复制
db.users.find(
    { status: "A",
      age: 50 }
)
登录后复制
See find()and$and for more information.
SELECT *
FROM users
WHERE status = "A"
OR age = 50
登录后复制
db.users.find(
    { $or: [ { status: "A" } ,
             { age: 50 } ] }
)
登录后复制
See find()and$or for more information.
SELECT *
FROM users
WHERE age > 25
登录后复制
db.users.find(
    { age: { $gt: 25 } }
)
登录后复制
See find()and$gt for more information.
SELECT *
FROM users
WHERE age < 25
登录后复制
db.users.find(
   { age: { $lt: 25 } }
)
登录后复制
See find()and$lt for more information.
SELECT *
FROM users
WHERE age > 25
AND   age <= 50
登录后复制
db.users.find(
   { age: { $gt: 25, $lte: 50 } }
)
登录后复制
See find(),$gt, and $lte formore information.
SELECT *
FROM users
WHERE user_id like "%bc%"
登录后复制
db.users.find(
   { user_id: /bc/ }
)
登录后复制
See find()and$regex for more information.
SELECT *
FROM users
WHERE user_id like "bc%"
登录后复制
db.users.find(
   { user_id: /^bc/ }
)
登录后复制
See find()and$regex for more information.
SELECT *
FROM users
WHERE status = "A"
ORDER BY user_id ASC
登录后复制
db.users.find( { status: "A" } ).sort( { user_id: 1 } )
登录后复制
See find()andsort()for more information.
SELECT *
FROM users
WHERE status = "A"
ORDER BY user_id DESC
登录后复制
db.users.find( { status: "A" } ).sort( { user_id: -1 } )
登录后复制
See find()andsort()for more information.
SELECT COUNT(*)
FROM users
登录后复制
db.users.count()
登录后复制

or

db.users.find().count()
登录后复制
See find()andcount() formore information.
SELECT COUNT(user_id)
FROM users
登录后复制
db.users.count( { user_id: { $exists: true } } )
登录后复制

or

db.users.find( { user_id: { $exists: true } } ).count()
登录后复制
See find(),count(), and$exists for more information.
SELECT COUNT(*)
FROM users
WHERE age > 30
登录后复制
db.users.count( { age: { $gt: 30 } } )
登录后复制

or

db.users.find( { age: { $gt: 30 } } ).count()
登录后复制
See find(),count(), and$gt for more information.
SELECT DISTINCT(status)
FROM users
登录后复制
db.users.distinct( "status" )
登录后复制
See find()anddistinct()for more information.
SELECT *
FROM users
LIMIT 1
登录后复制
db.users.findOne()
登录后复制

or

db.users.find().limit(1)
登录后复制
See find(),findOne(),andlimit()for more information.
SELECT *
FROM users
LIMIT 5
SKIP 10
登录后复制
db.users.find().limit(5).skip(10)
登录后复制
See find(),limit(), andskip() formore information.
EXPLAIN SELECT *
FROM users
WHERE status = "A"
登录后复制
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
UPDATE users
SET status = "C"
WHERE age > 25
登录后复制
db.users.update(
   { age: { $gt: 25 } },
   { $set: { status: "C" } },
   { multi: true }
)
登录后复制
See update(),$gt, and $set for moreinformation.
UPDATE users
SET age = age + 3
WHERE status = "A"
登录后复制
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

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

热工具

记事本++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教程
1660
14
CakePHP 教程
1417
52
Laravel 教程
1311
25
PHP教程
1261
29
C# 教程
1234
24
如何在Debian上配置MongoDB自动扩容 如何在Debian上配置MongoDB自动扩容 Apr 02, 2025 am 07:36 AM

本文介绍如何在Debian系统上配置MongoDB实现自动扩容,主要步骤包括MongoDB副本集的设置和磁盘空间监控。一、MongoDB安装首先,确保已在Debian系统上安装MongoDB。使用以下命令安装:sudoaptupdatesudoaptinstall-ymongodb-org二、配置MongoDB副本集MongoDB副本集确保高可用性和数据冗余,是实现自动扩容的基础。启动MongoDB服务:sudosystemctlstartmongodsudosys

使用 Composer 解决推荐系统的困境:andres-montanez/recommendations-bundle 的实践 使用 Composer 解决推荐系统的困境:andres-montanez/recommendations-bundle 的实践 Apr 18, 2025 am 11:48 AM

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

MongoDB在Debian上的高可用性如何保障 MongoDB在Debian上的高可用性如何保障 Apr 02, 2025 am 07:21 AM

本文介绍如何在Debian系统上构建高可用性的MongoDB数据库。我们将探讨多种方法,确保数据安全和服务持续运行。关键策略:副本集(ReplicaSet):利用副本集实现数据冗余和自动故障转移。当主节点出现故障时,副本集会自动选举新的主节点,保证服务的持续可用性。数据备份与恢复:定期使用mongodump命令进行数据库备份,并制定有效的恢复策略,以应对数据丢失风险。监控与报警:部署监控工具(如Prometheus、Grafana)实时监控MongoDB的运行状态,并

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

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

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

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

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

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数据库,擅长处理海

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

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

See all articles
SQL Delete Statements MongoDB remove() Statements Reference
DELETE FROM users
WHERE status = "D"
登录后复制
db.users.remove( { status: "D" } )
登录后复制
See remove()for more information.
DELETE FROM users
登录后复制
db.users.remove( )
登录后复制
See remove()for more information.