37

I wasn't able to find any information on the max length for a string data type in MongoDB on the main mongodb.org site. I'm coming from a relational database background and there are usually max lengths.

ggorlen
  • 44,755
  • 7
  • 76
  • 106
Goalie
  • 3,045
  • 5
  • 35
  • 46

4 Answers4

48

This other question should answer your question:

Documents larger than 4MB (when converted to BSON) cannot be saved to the database. This is a somewhat arbitrary limit (and may be raised in the future); it is mostly to prevent bad schema design and ensure consistent performance.

Note that in the picked answer for that question the commenter mentions that it could be as large as 8mb or 16mb now.

So to answer your question, it's not necessarily that a single string can only be a certain length, but rather that the whole document must be under 16MB.

Community
  • 1
  • 1
Ryan Bigg
  • 106,965
  • 23
  • 235
  • 261
5

See this:

The maximum BSON document size is 16 megabytes. The maximum document size helps ensure that a single document cannot use excessive amount of RAM or, during transmission, excessive amount of bandwidth. To store documents larger than the maximum size, MongoDB provides the GridFS API.

afruzan
  • 1,454
  • 19
  • 20
0

In MongoDB, the maximum size for a document (which includes a string data type) is 16 megabytes (MB). However, keep in mind that strings within a document count toward this size limit. The exact maximum length for a string data type in Ruby and MongoDB would depend on the overall structure of your document and the data it contains.

-1

Follow here

The maximum BSON document size is 16 megabytes.

The maximum document size helps ensure that a single document cannot use excessive amount of RAM or, during transmission, excessive amount of bandwidth. To store documents larger than the maximum size, MongoDB provides the GridFS API. See mongofiles and the documentation for your driver for more information about GridFS.

Community
  • 1
  • 1
Jack lee
  • 39
  • 1
  • 5