Table of Contents
Create and Alter
Insert
Select
Update Records
Delete Records
Home Database Mysql Tutorial mongodb安装笔记【服务没有及时响应或控制请求】

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

Jun 07, 2016 pm 03:28 PM
mongodb response Install control Serve notes

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'
Copy after login
日志需要指定具体的文件,比如MongoLog.log 之前没有置顶就报错【服务没有及时响应或控制请求】

安装、删除服务指令

mongod --install

mongod --service

mongod --remove

mongod --reinstall

或者

C:\mongodb\bin\mongod.exe --remove
Copy after login

启动服务

net start Mongodb
Copy after login
停止服务
net stop Mongodb
Copy after login
测试简单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
Copy after login

下面从官网摘抄下来的普通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)
)
Copy after login

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"
 } )
Copy after login

However, you can also explicitly create a collection:

db.createCollection("users")
Copy after login
Seeinsert() anddb.createCollection()for more information.
ALTER TABLE users
ADD join_date DATETIME
Copy after login

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 }
)
Copy after login
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
Copy after login

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

or

db.users.find().count()
Copy after login
See find()andcount() formore information.
SELECT COUNT(user_id)
FROM users
Copy after login
db.users.count( { user_id: { $exists: true } } )
Copy after login

or

db.users.find( { user_id: { $exists: true } } ).count()
Copy after login
See find(),count(), and$exists for more information.
SELECT COUNT(*)
FROM users
WHERE age > 30
Copy after login
db.users.count( { age: { $gt: 30 } } )
Copy after login

or

db.users.find( { age: { $gt: 30 } } ).count()
Copy after login
See find(),count(), and$gt for more information.
SELECT DISTINCT(status)
FROM users
Copy after login
db.users.distinct( "status" )
Copy after login
See find()anddistinct()for more information.
SELECT *
FROM users
LIMIT 1
Copy after login
db.users.findOne()
Copy after login

or

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

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to configure MongoDB automatic expansion on Debian How to configure MongoDB automatic expansion on Debian Apr 02, 2025 am 07:36 AM

This article introduces how to configure MongoDB on Debian system to achieve automatic expansion. The main steps include setting up the MongoDB replica set and disk space monitoring. 1. MongoDB installation First, make sure that MongoDB is installed on the Debian system. Install using the following command: sudoaptupdatesudoaptinstall-ymongodb-org 2. Configuring MongoDB replica set MongoDB replica set ensures high availability and data redundancy, which is the basis for achieving automatic capacity expansion. Start MongoDB service: sudosystemctlstartmongodsudosys

Use Composer to solve the dilemma of recommendation systems: andres-montanez/recommendations-bundle Use Composer to solve the dilemma of recommendation systems: andres-montanez/recommendations-bundle Apr 18, 2025 am 11:48 AM

When developing an e-commerce website, I encountered a difficult problem: how to provide users with personalized product recommendations. Initially, I tried some simple recommendation algorithms, but the results were not ideal, and user satisfaction was also affected. In order to improve the accuracy and efficiency of the recommendation system, I decided to adopt a more professional solution. Finally, I installed andres-montanez/recommendations-bundle through Composer, which not only solved my problem, but also greatly improved the performance of the recommendation system. You can learn composer through the following address:

How to ensure high availability of MongoDB on Debian How to ensure high availability of MongoDB on Debian Apr 02, 2025 am 07:21 AM

This article describes how to build a highly available MongoDB database on a Debian system. We will explore multiple ways to ensure data security and services continue to operate. Key strategy: ReplicaSet: ReplicaSet: Use replicasets to achieve data redundancy and automatic failover. When a master node fails, the replica set will automatically elect a new master node to ensure the continuous availability of the service. Data backup and recovery: Regularly use the mongodump command to backup the database and formulate effective recovery strategies to deal with the risk of data loss. Monitoring and Alarms: Deploy monitoring tools (such as Prometheus, Grafana) to monitor the running status of MongoDB in real time, and

Navicat's method to view MongoDB database password Navicat's method to view MongoDB database password Apr 08, 2025 pm 09:39 PM

It is impossible to view MongoDB password directly through Navicat because it is stored as hash values. How to retrieve lost passwords: 1. Reset passwords; 2. Check configuration files (may contain hash values); 3. Check codes (may hardcode passwords).

What is the CentOS MongoDB backup strategy? What is the CentOS MongoDB backup strategy? Apr 14, 2025 pm 04:51 PM

Detailed explanation of MongoDB efficient backup strategy under CentOS system This article will introduce in detail the various strategies for implementing MongoDB backup on CentOS system to ensure data security and business continuity. We will cover manual backups, timed backups, automated script backups, and backup methods in Docker container environments, and provide best practices for backup file management. Manual backup: Use the mongodump command to perform manual full backup, for example: mongodump-hlocalhost:27017-u username-p password-d database name-o/backup directory This command will export the data and metadata of the specified database to the specified backup directory.

How to choose a database for GitLab on CentOS How to choose a database for GitLab on CentOS Apr 14, 2025 pm 04:48 PM

GitLab Database Deployment Guide on CentOS System Selecting the right database is a key step in successfully deploying GitLab. GitLab is compatible with a variety of databases, including MySQL, PostgreSQL, and MongoDB. This article will explain in detail how to select and configure these databases. Database selection recommendation MySQL: a widely used relational database management system (RDBMS), with stable performance and suitable for most GitLab deployment scenarios. PostgreSQL: Powerful open source RDBMS, supports complex queries and advanced features, suitable for handling large data sets. MongoDB: Popular NoSQL database, good at handling sea

Major update of Pi Coin: Pi Bank is coming! Major update of Pi Coin: Pi Bank is coming! Mar 03, 2025 pm 06:18 PM

PiNetwork is about to launch PiBank, a revolutionary mobile banking platform! PiNetwork today released a major update on Elmahrosa (Face) PIMISRBank, referred to as PiBank, which perfectly integrates traditional banking services with PiNetwork cryptocurrency functions to realize the atomic exchange of fiat currencies and cryptocurrencies (supports the swap between fiat currencies such as the US dollar, euro, and Indonesian rupiah with cryptocurrencies such as PiCoin, USDT, and USDC). What is the charm of PiBank? Let's find out! PiBank's main functions: One-stop management of bank accounts and cryptocurrency assets. Support real-time transactions and adopt biospecies

MongoDB and relational database: a comprehensive comparison MongoDB and relational database: a comprehensive comparison Apr 08, 2025 pm 06:30 PM

MongoDB and relational database: In-depth comparison This article will explore in-depth the differences between NoSQL database MongoDB and traditional relational databases (such as MySQL and SQLServer). Relational databases use table structures of rows and columns to organize data, while MongoDB uses flexible document-oriented models to better suit the needs of modern applications. Mainly differentiates data structures: Relational databases use predefined schema tables to store data, and relationships between tables are established through primary keys and foreign keys; MongoDB uses JSON-like BSON documents to store them in a collection, and each document structure can be independently changed to achieve pattern-free design. Architectural design: Relational databases need to pre-defined fixed schema; MongoDB supports

See all articles
SQL Delete Statements MongoDB remove() Statements Reference
DELETE FROM users
WHERE status = "D"
Copy after login
db.users.remove( { status: "D" } )
Copy after login
See remove()for more information.
DELETE FROM users
Copy after login
db.users.remove( )
Copy after login
See remove()for more information.