@@ -49,11 +49,11 @@ mongoc_dump_collection (mongoc_client_t *client,
49
49
{
50
50
mongoc_collection_t * col ;
51
51
mongoc_cursor_t * cursor ;
52
- mongoc_stream_t * stream ;
53
52
mongoc_iovec_t iov ;
54
53
const bson_t * doc ;
55
54
bson_error_t error ;
56
55
bson_t query = BSON_INITIALIZER ;
56
+ FILE * stream ;
57
57
char * path ;
58
58
int ret = EXIT_SUCCESS ;
59
59
@@ -68,7 +68,7 @@ mongoc_dump_collection (mongoc_client_t *client,
68
68
}
69
69
#endif
70
70
71
- stream = mongoc_stream_file_new_for_path (path , O_RDWR | O_CREAT , 0664 );
71
+ stream = fopen (path , "w" );
72
72
if (!stream ) {
73
73
fprintf (stderr , "Failed to open \"%s\", aborting.\n" , path );
74
74
exit (EXIT_FAILURE );
@@ -78,28 +78,23 @@ mongoc_dump_collection (mongoc_client_t *client,
78
78
cursor = mongoc_collection_find (col , MONGOC_QUERY_NONE , 0 , 0 , 0 ,
79
79
& query , NULL , NULL );
80
80
81
- while (mongoc_cursor_more (cursor ) &&
82
- !mongoc_cursor_error (cursor , & error )) {
83
- if (mongoc_cursor_next (cursor , & doc )) {
84
- iov .iov_len = doc -> len ;
85
- iov .iov_base = (void * )bson_get_data (doc );
86
- if (doc -> len != mongoc_stream_writev (stream , & iov , 1 , 0 )) {
87
- fprintf (stderr , "Failed to write %u bytes to %s\n" ,
88
- doc -> len , path );
89
- ret = EXIT_FAILURE ;
90
- goto cleanup ;
91
- }
81
+ while (mongoc_cursor_next (cursor , & doc )) {
82
+ if (BSON_UNLIKELY (doc -> len != fwrite (bson_get_data (doc ), 1 , doc -> len , stream ))) {
83
+ fprintf (stderr , "Failed to write %u bytes to %s\n" ,
84
+ doc -> len , path );
85
+ ret = EXIT_FAILURE ;
86
+ goto cleanup ;
92
87
}
93
88
}
94
89
95
90
if (mongoc_cursor_error (cursor , & error )) {
96
- fprintf (stderr , "%s\n" , error .message );
91
+ fprintf (stderr , "ERROR: %s\n" , error .message );
97
92
ret = EXIT_FAILURE ;
98
93
}
99
94
100
95
cleanup :
101
96
bson_free (path );
102
- mongoc_stream_destroy (stream );
97
+ fclose (stream );
103
98
mongoc_cursor_destroy (cursor );
104
99
mongoc_collection_destroy (col );
105
100
@@ -245,11 +240,14 @@ main (int argc,
245
240
}
246
241
}
247
242
243
+ #if 0
248
244
uri = bson_strdup_printf ("mongodb://%s:%hu/%s?ssl=%s" ,
249
245
host ,
250
246
port ,
251
247
database ? database : "" ,
252
248
ssl ? "true" : "false" );
249
+ #endif
250
+ uri = NULL ;
253
251
254
252
if (!(client = mongoc_client_new (uri ))) {
255
253
fprintf (stderr , "Invalid connection URI: %s\n" , uri );
0 commit comments