The driver should fail fast on document bounds. For large document, i.e. the ones going beyond the 16 MB document limit (or whatever server publishes to be the limits) the server may either return an error or close the connection which leaves the client with a failed socket but without any specific error information based on which it make any intelligent decision to skip documents.
It would be much more efficient if the driver layer can perform the necessary validations in terms of document size etc. The java driver already performs these checks before sending the request to the MongoDB instance.
// CC insert.c -o insert -Isrc/mongoc/ -I src/libbson/src/bson/ -L src/libbson/.libs/ -L .libs/ -lbson -lmongoc-1.0 #include "mongoc.h" const char* const TEST_NS = "test.big_document"; int main(int argc, const char* argv[]) { mongoc_client_t *client; char longStr[5 * 1024*1024] = {}; fprintf(stderr, "Will continue with memsetting the values.\n"); memset(longStr, 'a', sizeof(longStr)); longStr[sizeof(longStr) - 1] = '\0'; mongoc_init(); client = mongoc_client_new("mongodb://127.0.0.1:27017"); if (!client) { fprintf(stderr, "Failed to make client connection to mongod"); return 1; } fprintf(stderr, "Will continue with creating the object.\n"); bson_t *doc; doc = bson_new(); BSON_APPEND_UTF8(doc, "key_1", longStr); BSON_APPEND_UTF8(doc, "key_2", longStr); BSON_APPEND_UTF8(doc, "key_3", longStr); BSON_APPEND_UTF8(doc, "key_4", longStr); fprintf(stderr, "Completed creating the document.. will continue with insertion.\n"); mongoc_collection_t *collection = mongoc_client_get_collection (client, "test", "test"); bson_error_t error; if (!mongoc_collection_insert(collection, MONGOC_INSERT_NONE, doc, NULL, &error)) { printf ("%s\n", error.message); } bson_destroy(doc); mongoc_collection_destroy(collection); mongoc_client_destroy(client); return 0; }
- is depended on by
-
DRIVERS-275 Drivers should check encoded operation size on client side
- Closed
- is related to
-
CDRIVER-1023 Support reading 16mb using the new find commands
- Closed
-
SERVER-12305 Allow command request and response BSON objects to exceed 16MB
- Backlog
- related to
-
CDRIVER-654 Ordered bulk insert continues past oversized doc
- Closed
- links to