Maison > base de données > tutoriel mysql > mongodb安装笔记【服务没有及时响应或控制请求】

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Libérer: 2016-06-07 15:28:08
original
1778 Les gens l'ont consulté

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

安装、删除服务指令

mongod --install

mongod --service

mongod --remove

mongod --reinstall

或者

C:\mongodb\bin\mongod.exe --remove
Copier après la connexion

启动服务

net start Mongodb
Copier après la connexion
停止服务
net stop Mongodb
Copier après la connexion
测试简单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
Copier après la connexion

下面从官网摘抄下来的普通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)
)
Copier après la connexion

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"
 } )
Copier après la connexion

However, you can also explicitly create a collection:

db.createCollection("users")
Copier après la connexion
Seeinsert() anddb.createCollection()for more information.
ALTER TABLE users
ADD join_date DATETIME
Copier après la connexion

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 }
)
Copier après la connexion
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
Copier après la connexion

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

or

db.users.find().count()
Copier après la connexion
See find()andcount() formore information.
SELECT COUNT(user_id)
FROM users
Copier après la connexion
db.users.count( { user_id: { $exists: true } } )
Copier après la connexion

or

db.users.find( { user_id: { $exists: true } } ).count()
Copier après la connexion
See find(),count(), and$exists for more information.
SELECT COUNT(*)
FROM users
WHERE age > 30
Copier après la connexion
db.users.count( { age: { $gt: 30 } } )
Copier après la connexion

or

db.users.find( { age: { $gt: 30 } } ).count()
Copier après la connexion
See find(),count(), and$gt for more information.
SELECT DISTINCT(status)
FROM users
Copier après la connexion
db.users.distinct( "status" )
Copier après la connexion
See find()anddistinct()for more information.
SELECT *
FROM users
LIMIT 1
Copier après la connexion
db.users.findOne()
Copier après la connexion

or

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

Étiquettes associées:
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Derniers numéros
mongodb démarrer
Depuis 1970-01-01 08:00:00
0
0
0
mongodb _id renommer
Depuis 1970-01-01 08:00:00
0
0
0
Utilisation de symfony2 mongodb
Depuis 1970-01-01 08:00:00
0
0
0
Compréhension des paramètres de mongodb
Depuis 1970-01-01 08:00:00
0
0
0
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
SQL Delete Statements MongoDB remove() Statements Reference
DELETE FROM users
WHERE status = "D"
Copier après la connexion
db.users.remove( { status: "D" } )
Copier après la connexion
See remove()for more information.
DELETE FROM users
Copier après la connexion
db.users.remove( )
Copier après la connexion
See remove()for more information.