Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8610185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:04:09+00:00 2026-06-12T04:04:09+00:00

I have a mapping in MongoDB as type hash, named meta_info which simply holds

  • 0

I have a mapping in MongoDB as type hash, named “meta_info” which simply holds a key/value list of something, I’d like to make it to a form in Symfony2 which can be enhanced dynamically (with js), to have it look (basically) like this:

<input type="text" name="meta_info[key][]" /><input type="text" name="meta_info[field][]">   [- remove row]
<input type="text" name="meta_info[key][]" /><input type="text" name="meta_info[field][]">   [+ add row]

My first ideas were to make two textfields (key/value) which can be duplicated using js (thats not the problem) and which get converted to a json string onSubmit and converted back to an array inside my setter method of my Document class.. But this seems kinda dirty..

I was also thinking about embedding forms (which works very well with embedded documents now in sf2.1!) – but I don’t know how to achieve this for a simple key/value hash (which should also be stored like that in mongodb)

Thanks for any ideas and approaches!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T04:04:10+00:00Added an answer on June 12, 2026 at 4:04 am

    Thinking about this in terms of Symfony forms, you likely want to have a dynamic collection of inner forms, each of which has key and value input fields. I can’t think of another implementation to handle this case, as you’re essentially foregoing any notion of a schema by using a hash field. That’s mainly what distinguishes this case from embedded documents in ODM (which would have mappings), even though MongoDB is going to store in the same manner (nested objects).

    One alternative implementation is to have an EmbedMany relationship of documents that contain key and value properties. OpenSky uses this internally to represent product attributes. It consumes a bit more storage in the MongoDB document, since you have an array of objects with key and value fields instead of a single object of key/value pairs, but there are some clear benefits:

    • The structure can be mapped, which plays nicely with your existing ODM schema.
    • Since you have a model for each key/value pair, it’s more natural to represent this with Symfony forms.
    • Perhaps most importantly if you’re going to query by this data, you can take advantage of multi-key indexing to index dynamic keys and values and then use $elemMatch queries for key/value lookups. If you were just using a hash field with dynamic keys, there would be no straightforward way to index multiple keys (each distinct field path would require an explicit index, or explicit mention in a compound index).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to have a mapping which maps two string into one string.
I have a mapping like this: HasMany(x => x.Orders).KeyColumn(CustomerID); Which is causing a constraint
I have a mapping that looks like this: <class name=Record> <map name=Values> <key column=RecordFK/>
I have following mapping definitions: <class name=Role table=Role optimistic-lock=version > <id name=Id type=Int32 unsaved-value=0
I have hash mapping H = { alc => AL, alco => AL, alcoh
I would like to have a mapping function that does this: public static void
Hi everyone and couchdb pros, I have a mapping setup like such: class Product(BaseModel):
I have a mapping like this: @ManyToMany(cascade = CascadeType.PERSIST) @JoinTable( name=product_product_catalog, joinColumns={@JoinColumn(name=product_catalog, referencedColumnName=product_catalog)}, inverseJoinColumns={@JoinColumn(name=product,
I have a mapping from Strings to List of Strings in Java: 100 ->
I have a mapping in NHibernate that works like so: <?xml version=1.0 encoding=utf-8 ?>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.