Saturday, 15 August 2015

mongoose - Mongodb model to store user/item specific data -



mongoose - Mongodb model to store user/item specific data -

the case: there users in system, , there static documents (like books) each user may work documents , have specific state/settings (like current position/page in document, bookmarks/notes) each of docs.

what improve way store user , document specific info in flat collection 2 keys userid , documentid or collection have _id equal userid , nested array of subdocuments have _id equal documentid (in scenario collection used storing non-document specific user data)?

1st scenaroio: find({userid: ..., documentid:...})

2nd scenaroio: findby({_id:...}), find sub doc _id equal documentid

pros of 1st scenario:

1) believe quicker find , save operations.

cons of 1st scenario:

1) greater amount of documents

2) no way store non-doc related user-specific info in collection

pros of 2nd scenario:

1) improve representation of info relations (subjective though)

2) makes possible utilize same collection store other non particular document related user data.

cons of 2nd:

1) more hard search , more hard save operations (i'm using using mongoose odm , code not complex), , think operations less speedy in 1st scenario.

some things consider:

1) in general in read operations select 1 document specific info

2) need save 1 document specific info (for illustration periodical saving of position in document user working with).

3) user/document state may have nested arrays (bookmarks, notes) have changed (docs inserted/removed)

taking considerations 1st scenario more suitable task, hear pro opinions, whether 2 scenarios differ greatly.

what actual access paths? start user id, , documents user reads? or start document , search users, read it? document object lightweight (just title , author , suchlike information) or heavyweight (includes contents)? if documents heavyweight, i'd maintain them in separate collection , go scenario 2.

basically scenario 1 mimics relational solution , scenario looks object model.

i believe object models describe reality improve , more efficient.

so i'd go scenario 2, unless search readers book.

mongodb mongoose

No comments:

Post a Comment