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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 15:28:08
Original
1769 people have browsed it

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.

source:php.cn
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
Latest Issues
mongodb start
From 1970-01-01 08:00:00
0
0
0
linux - ubuntu14 error installing mongodb
From 1970-01-01 08:00:00
0
0
0
Use of symfony2 mongodb
From 1970-01-01 08:00:00
0
0
0
mongodb _id rename
From 1970-01-01 08:00:00
0
0
0
Parameter understanding of mongodb
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
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.