MongoDB Http Interface

本文介绍了MongoDB的HTTP接口,包括基于不同语言的REST接口,如Ruby的DrowsyDromedary、Node.js的MongoDB Rest、Java的Mongodb Java REST server和Python的Sleepy Mongoose。还提及了HTTP控制台、简单REST接口及副本集管理UI的相关信息,如访问端口、安全设置等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

HTTP Interface

REST Interfaces

DrowsyDromedary (Ruby)

DrowsyDromedary is a REST layer for MongoDB based on Ruby.

MongoDB Rest (Node.js)

MongoDB Rest is an alpha REST interface to MongoDB that uses the MongoDB Node Native driver.

Mongodb Java REST server

Mongodb Java REST server based on Jetty.

HTTP Interfaces

Sleepy Mongoose (Python)

Sleepy Mongoose is a full featured HTTP interface for MongoDB.

HTTP Console

MongoDB provides a simple http interface listing information of interest to administrators. This interface may be accessed at the port with numeric value 1000 more than the configured mongod port. The default port for the http interface is 28017. To access the http interface an administrator may, for example, point a browser to http://localhost:28017 if mongod is running with the default port on the local machine.

../../_images/http-interface-console.png

Here is a description of the informational elements of the http interface:

elementdescription
db versiondatabase version information
git hashdatabase version developer tag
sys infomongod compilation environment
dblockedindicates whether the primary mongod mutex is held
uptimetime since this mongod instance was started
assertionsany software assertions that have been raised by this mongodinstance
replInfoinformation about replication configuration
currentOpmost recent client request
# databasesnumber of databases that have been accessed by this mongodinstance
curclientlast database accessed by this mongod instance
Cursorsdescribes outstanding client cursors
masterwhether this mongod instance has been designated a master
slavewhether this mongod instance has been designated a slave
initialSyncCompletedwhether this slave or repl pair node has completed an initial clone of the mongod instance it is replicating
DBTOPDisplays the total time the mongod instance has devoted to each listed collection, as well as the percentage of available time devoted to each listed collection recently and the number of reads, writes, and total calls made recently
dtTiming information about the primary mongod mutex

HTTP Console Security

If security is configured for a mongod instance, authentication is required for a client to access the http interface from another machine.

Simple REST Interface

The mongod process includes a simple REST interface, with no support for insert/update/remove operations, as a convenience – it is generally used for monitoring/alerting scripts or administrative tasks. For full REST capabilities we recommend using an external tool such asSleepy.Mongoose.

v1.4+: This interface is disabled by default. Use --rest on the command line to enable.

To get the contents of a collection (note the trailing slash):

http://127.0.0.1:28017/databaseName/collectionName/

To add a limit:

http://127.0.0.1:28017/databaseName/collectionName/?limit=-10

To skip:

http://127.0.0.1:28017/databaseName/collectionName/?skip=5

To query for {a : 1}:

http://127.0.0.1:28017/databaseName/collectionName/?filter_a=1

Separate conditions with an &:

http://127.0.0.1:28017/databaseName/collectionName/?filter_a=1&limit=-10

Same as db.$cmd.findOne({listDatabase:1}) on the admin database in the shell:

http://localhost:28017/admin/$cmd/?filter_listDatabases=1&limit=1

To count documents in a collection:

http://host:port/db/$cmd/?filter_count=collection&limit=1

JSON in the simple REST interface

The simple ReST interface uses strict JSON (as opposed to the shell, which uses Dates, regular expressions, etc.). To display non-JSON types, the web interface wraps them in objects and uses the key for the type. For example:

# ObjectIds just become strings
"_id" : "4a8acf6e7fbadc242de5b4f3"

# dates
"date" : { "$date" : 1250609897802 }

# regular expressions
"match" : { "$regex" : "foo", "$options" : "ig" }

The code type has not been implemented yet and causes the DB to crash if you try to display it in the browser.

See Mongo Extended JSON for details.

Replica Set Admin UI

The mongod process includes a simple administrative UI for checking the status of a replica set.

To use, first enable --rest from the mongod command line. The rest port is the db port plus 1000 (thus, the default is 28017). Be sure this port is secure before enabling this.

Then you can navigate to http://<hostname>:28017/ in your web browser. Once there, click Replica Set Status (/_replSet) to move to the Replica Set Status page.

../../_images/http-interface-rs.png

# HttpInterface Windows上C++封装的HTTP库,包含三种实现模式(WinInet、WinHttp、socket) 主要实现了HTTP的get\post方法,下载到内存、下载到本地文件,回调下载进度等接口 测试程序中展现了常用的几个方法。 接口类声明: class IHttpBase { public: virtual void SetDownloadCallback(IHttpCallback* pCallback, void* pParam)= 0; virtual bool DownloadFile(LPCWSTR lpUrl, LPCWSTR lpFilePath)= 0; virtual bool DownloadToMem(LPCWSTR lpUrl, OUT void** ppBuffer, OUT int* nSize)= 0; virtual void FreeInstance()= 0; virtual HttpInterfaceError GetErrorCode()= 0; }; //////////////////////////////////////////////////////////////////////////////////// //HTTP请求接口类 class IWininetHttp :public IHttpBase { public: //HTTP请求功能 virtual string Request(LPCSTR lpUrl, HttpRequest type, LPCSTR lpPostData = NULL, LPCSTR lpHeader = NULL)= 0; virtual string Request(LPCWSTR lpUrl, HttpRequest type, LPCSTR lpPostData = NULL, LPCWSTR lpHeader = NULL)= 0; }; /////////////////////////////////////////////////////////////////////////////////////// //HTTP socket类 class ISocketHttp :public IHttpBase { public: virtual LPCWSTR GetIpAddr()const= 0; }; /////////////////////////////////////////////////////////////////////////////////////// //WinHttp类 class IWinHttp : public IWininetHttp { public: //设置超时时间,单位:毫秒 virtual void SetTimeOut(int dwConnectTime, int dwSendTime, int dwRecvTime)= 0; }; 能力有限,有bug欢迎指正 email:jelinyao@163.com
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值