1 bool
copydb(mongoc_client_t * client,const char * other_host_and_port)2 copydb (mongoc_client_t *client, const char *other_host_and_port)
3 {
4    mongoc_database_t *admindb;
5    bson_t *command;
6    bson_t reply;
7    bson_error_t error;
8    bool res;
9 
10    BSON_ASSERT (other_host_and_port);
11    /* Must do this from the admin db */
12    admindb = mongoc_client_get_database (client, "admin");
13 
14    command = BCON_NEW ("copydb",
15                        BCON_INT32 (1),
16                        "fromdb",
17                        BCON_UTF8 ("test"),
18                        "todb",
19                        BCON_UTF8 ("test2"),
20 
21                        /* If you want from a different host */
22                        "fromhost",
23                        BCON_UTF8 (other_host_and_port));
24    res =
25       mongoc_database_command_simple (admindb, command, NULL, &reply, &error);
26    if (!res) {
27       fprintf (stderr, "Error with copydb: %s\n", error.message);
28       goto cleanup;
29    }
30 
31    /* Do something with the reply */
32    print_res (&reply);
33 
34 cleanup:
35    bson_destroy (&reply);
36    bson_destroy (command);
37    mongoc_database_destroy (admindb);
38 
39    return res;
40 }
41