Best practice for document structure

Hi,
suppose to have a bucket with 1 000 000 documents

Also suppose to have a note document.
Each note document is associated to a user.
The note can be edited and deleted.
The number of notes shouldn’t be very large, because it’s probable that the user delete old notes.
The notes are retrive all in one call to the server.

I was wondering what is better between these two scenario:

  1. Have a single document with an array of notes. In this case, i would search only for a single document.
  2. Have a document for each note. In that case i would search for a lot of document during the server call.

My question is: is there a difference to search for a single document(1st approach) rather that for, let say, 100 documents(2nd approach)?

Thanks in advance

If you index everything correctly there shouldn’t be a massive different in performance between the two cases.

If you store it in one document you have to stay inside the total size of a Couchbase document (20MB total). Having different notes gives you the option to put a TTL (time to live) on the notes, so that old notes can automatically be removed after a specified time. It’s also easier/quicker to retrieve one note for a user instead of going through a collection.

Also, are you updating one note or many notes at the same time? Having a single doc will ensure that all the changes are written whereas having multiple docs mean that they will be spread over the cluster. Having a node down will mean that you might have failed writes until the node is recovered or cluster rebalanced.

1 Like