i working first application in symfony2/mongodb, have store articles , these articles have tags, keywords , related images. @ moment storing these information that:
"category" : [ "category1", " category2", " category3" ],
but saw few examples saying
"category" : "category1, category2, category3",
so guessing 1 best way it?
if use array, have following advantages:
- you can access each item directly index.
- you can perform queries directly on array using operators $in, $nin , $elemmatch
if use string, have to:
- split
,
in order looping - user text based searching in query, slow
one thing need keep in mind regarding arrays inside mongodb document should not large. arrays can large, , if pushes size of document beyond 16 mb, cause issues, 16 mb maximum allowed size single document.
in use case, can split off contents of array separate collection , created references.
Comments
Post a Comment