> 데이터 베이스 > MySQL 튜토리얼 > mongodb安装笔记【服务没有及时响应或控制请求】

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
풀어 주다: 2016-06-07 15:28:08
원래의
1777명이 탐색했습니다.

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으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
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.