MONGOC_GRIDFS_BUCKET_T - Online Linux Manual PageSection : 3
Updated : Feb 04, 2021
Source : 1.17.4
Note : libmongoc

NAMEmongoc_gridfs_bucket_t − mongoc_gridfs_bucket_t

SYNOPSIS #include <mongoc/mongoc.h> typedef struct _mongoc_gridfs_bucket_t mongoc_gridfs_bucket_t;

DESCRIPTIONmongoc_gridfs_bucket_t provides a spec−compliant MongoDB GridFS implementation, superseding mongoc_gridfs_t​. See the ­GridFS MongoDB documentation​.

THREAD SAFETYmongoc_gridfs_bucket_t is NOT thread−safe and should only be used in the same thread as the owning mongoc_client_t​.

LIFECYCLEIt is an error to free a mongoc_gridfs_bucket_t before freeing all derived instances of mongoc_stream_t​. The owning mongoc_client_t must outlive the mongoc_gridfs_bucket_t​.

EXAMPLEexample−gridfs−bucket.c #include <stdio.h> #include <stdlib.h> #include <mongoc/mongoc.h> int main (int argc, char *argv[]) { const char *uri_string = "mongodb://localhost:27017/?appname=new−gridfs−example"; mongoc_client_t *client; mongoc_database_t *db; mongoc_stream_t *file_stream; mongoc_gridfs_bucket_t *bucket; mongoc_cursor_t *cursor; bson_t filter; bool res; bson_value_t file_id; bson_error_t error; const bson_t *doc; char *str; mongoc_init (); if (argc != 3) { fprintf (stderr, "usage: %s SOURCE_FILE_PATH FILE_COPY_PATH\n", argv[0]); return EXIT_FAILURE; } /* 1. Make a bucket. */ client = mongoc_client_new (uri_string); db = mongoc_client_get_database (client, "test"); bucket = mongoc_gridfs_bucket_new (db, NULL, NULL, &error); if (!bucket) { printf ("Error creating gridfs bucket: %s\n", error.message); return EXIT_FAILURE; } /* 2. Insert a file. */ file_stream = mongoc_stream_file_new_for_path (argv[1], O_RDONLY, 0); res = mongoc_gridfs_bucket_upload_from_stream ( bucket, "my−file", file_stream, NULL, &file_id, &error); if (!res) { printf ("Error uploading file: %s\n", error.message); return EXIT_FAILURE; } mongoc_stream_close (file_stream); mongoc_stream_destroy (file_stream); /* 3. Download the file in GridFS to a local file. */ file_stream = mongoc_stream_file_new_for_path (argv[2], O_CREAT | O_RDWR, 0); if (!file_stream) { perror ("Error opening file stream"); return EXIT_FAILURE; } res = mongoc_gridfs_bucket_download_to_stream ( bucket, &file_id, file_stream, &error); if (!res) { printf ("Error downloading file to stream: %s\n", error.message); return EXIT_FAILURE; } mongoc_stream_close (file_stream); mongoc_stream_destroy (file_stream); /* 4. List what files are available in GridFS. */ bson_init (&filter); cursor = mongoc_gridfs_bucket_find (bucket, &filter, NULL); while (mongoc_cursor_next (cursor, &doc)) { str = bson_as_canonical_extended_json (doc, NULL); printf ("%s\n", str); bson_free (str); } /* 5. Delete the file that we added. */ res = mongoc_gridfs_bucket_delete_by_id (bucket, &file_id, &error); if (!res) { printf ("Error deleting the file: %s\n", error.message); return EXIT_FAILURE; } /* 6. Cleanup. */ mongoc_stream_close (file_stream); mongoc_stream_destroy (file_stream); mongoc_cursor_destroy (cursor); bson_destroy (&filter); mongoc_gridfs_bucket_destroy (bucket); mongoc_database_destroy (db); mongoc_client_destroy (client); mongoc_cleanup (); return EXIT_SUCCESS; }

SEE ALSO • The ­MongoDB GridFS specification​. • The non spec−compliant mongoc_gridfs_t​.

AUTHORMongoDB, Inc

COPYRIGHT2017-present, MongoDB, Inc
0
Johanes Gumabo
Data Size   :   12,911 byte
man-mongoc_gridfs_bucket_t.3Build   :   2024-12-05, 20:55   :  
Visitor Screen   :   x
Visitor Counter ( page / site )   :   2 / 201,512
Visitor ID   :     :  
Visitor IP   :   3.149.254.229   :  
Visitor Provider   :   AMAZON-02   :  
Provider Position ( lat x lon )   :   39.962500 x -83.006100   :   x
Provider Accuracy Radius ( km )   :   1000   :  
Provider City   :   Columbus   :  
Provider Province   :   Ohio ,   :   ,
Provider Country   :   United States   :  
Provider Continent   :   North America   :  
Visitor Recorder   :   Version   :  
Visitor Recorder   :   Library   :  
Online Linux Manual Page   :   Version   :   Online Linux Manual Page - Fedora.40 - march=x86-64 - mtune=generic - 24.12.05
Online Linux Manual Page   :   Library   :   lib_c - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Online Linux Manual Page   :   Library   :   lib_m - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Data Base   :   Version   :   Online Linux Manual Page Database - 24.04.13 - march=x86-64 - mtune=generic - fedora-38
Data Base   :   Library   :   lib_c - 23.02.07 - march=x86-64 - mtune=generic - fedora.36

Very long time ago, I have the best tutor, Wenzel Svojanovsky . If someone knows the email address of Wenzel Svojanovsky , please send an email to johanes_gumabo@yahoo.co.id .
If error, please print screen and send to johanes_gumabo@yahoo.co.id
Under development. Support me via PayPal.