Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

Connecting

kchodorow edited this page Sep 14, 2010 · 4 revisions

Usage

http://localhost:27080/_connect

Description

Creates a connection to the database server. No database or collection name is necessary.

If no arguments are given, it tries to connect to “localhost:27017”.

Request Type

POST

Optional Arguments

  • server=database_server (string)
  • name=connection_name (string)

Return Values

On success:

{"ok" : 1, "host" : hostname, "port" : port_num}

On failure:

{"ok" : 0, "errmsg" : "could not connect", "host" : hostname, "port" : port_num}

Example

Connecting to a mongod server running locally on port 27017.

$ curl --data server=localhost:27017 'http://localhost:27080/_connect'

Multiple Connections

sleepy.mongoose can create multiple connections to the same (or different) database servers by labelling each connection. If no name parameter is passed to _connect, the connection is labelled “default” and that connection is used in subsequent commands (that do not specify a name).

$ curl http://localhost:27080/_connect # connects to localhost:27017 (A)
$ curl --data 'name=backup' http://localhost:27080/_connect # creates another connection (B)
$
$ curl http://localhost:27080/_find # uses A
$ curl http://localhost:27080/_find?name=backup # uses B

Example

If we had a master-slave setup, we could make separate connections to each so that we could send writes to the master and reads to the slave.

$ curl --data 'name=master&server=prod.master.example.com' http://localhost:27080/_connect
$ curl --data 'name=slave&server=prod.slave.example.com' http://localhost:27080/_connect

Now, whenever we send a request, we simply specify name=master to use the master server or name=slave to use the slave.

Clone this wiki locally