Form Data entry, long strings of text, and design question

Hello,

I am curious if the community has any feedback here. I am new to mongo, with little to no experience with SQL. So a bit of guidance here would definitely help me tremendously.

I have been looking for more information about the best way to store a fair amount of text as a string in a document. Let’s say that a user simply enters a string of text that could be 10 paragraphs in length. So, like a 10KB string.

First of all, would this be OK to do in Mongo? I haven’t been able to find a specific example of this long string of text yet, searching online.

  • I was also thinking about a parent reference for this particular document. So the document would have a field of, “created_by”, and the associated “_id” of the user who input this information.

Also, in terms of design I have let’s say… 25 different pages that a user will read, learn about, and provide feedback on… sort of how a content management system (CMS), might allow a user to save data entry for a blog post. Considering repeat data entry fields like the above, would

  • (1) each page be better maintained as separate collections (to store the data entry for the particular page)?..
  • or (2) perhaps one large collection with varying documents, depending on what page the user saved data for? I think this later case would also mean a very large schema of different fields.

So perhaps (1) is the better option… which I think would mean one Schema for one page that contains different questions/answers per each page.

Please remember I am a noob here! So I am open to any feedback or questions.

Thanks.

-Will

Hello @Will_M, welcome to the forum!

You can store your data in the MongoDB database. In general, you can find some relevant information in the MongoDB Manual (example topics are Data Modeling and Introduction).

Here is some information related to your questions:

> I have been looking for more information about the best way to store a fair amount of text as a string in a document. Let’s say that a user simply enters a string of text that could be 10 paragraphs in length. So, like a 10KB string.

Yes, you can store text in the database. A document can store upto 16 Megabytes of data. The text data can be stored as data type “string”.


> I was also thinking about a parent reference for this particular document. So the document would have a field of, “created_by”, and the associated “_id” of the user who input this information.

You can store your data using similar structure in a document:

{
    _id: ObjectId("626f55009a73985c1a5cba0c"),
    content: "Hello world...",
    created_by: "some_author_id",
    created_date: ISODate("2022-05-02T03:43:38.637Z"),
    // ...
}

> …25 different pages that a user will read, learn about, and provide feedback on…

You can store a number of pages within the same document. The content can be structured as an array of strings or an array of sub-documents (as shown below).

{
    content: [
        "This is page 1 content, etc.",
        "This is page 2 content, and theer are more pages.",
        //... more pages ...
    ]
}

Or,

{
    content: [
        { page: 1, text: "This is page 1 content, etc.", other_info: "..." },
        { page: 2, text: "This is page 2 content, and there are more pages.", other_info: "..." },
        //... more pages ...
    ]
}