-
Notifications
You must be signed in to change notification settings - Fork 107
Connecting
http://localhost:27080/_connect
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”.
POST
-
server=database_server
(string) -
name=connection_name
(string)
On success:
{"ok" : 1, "host" : hostname, "port" : port_num}
On failure:
{"ok" : 0, "errmsg" : "could not connect", "host" : hostname, "port" : port_num}
Connecting to a mongod server running locally on port 27017.
$ curl --data server=localhost:27017 'http://localhost:27080/_connect'
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
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.