首頁 > 資料庫 > mysql教程 > mongodb安装笔记【服务没有及时响应或控制请求】

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
發布: 2016-06-07 15:28:08
原創
1778 人瀏覽過

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
最新問題
mongodb 外網IP啟動失敗
來自於 1970-01-01 08:00:00
0
0
0
如何學習MongoDB?
來自於 1970-01-01 08:00:00
0
0
0
mongodb啟動
來自於 1970-01-01 08:00:00
0
0
0
linux - ubuntu14安裝mongodb出錯
來自於 1970-01-01 08:00:00
0
0
0
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
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.