Hello everybody, if I may be useful, I have created a device tracking environment (a sort of automatic census of the devices registered on the site) and the design could be similar to the one I was looking for.
First of all, we should identify what type of data could contain as much data as possible; for example, my new database in this tracking system is the device model. For each new device, a new database is created. Inside, each document will have the serial number as id, unique for the database and therefore for the device model; the data within the document are divided into three sections: - device characteristics (portable, mobile, PC, Mac, etc ...) - characteristics of the user (name, surname, nickname, telephone number, credit card, etc ...) - report to the site (pages visited (array), number of daily visits etc ...) All this by partitioning databases and documents into logical partitions based on the date (time stamp format 20210409). Below, an excerpt of the code that manages the new databases and new documents, to give an idea (the software is written in powershell [7] on an Ubuntu Server machine, using my open-source module PSCouchDB<https://github.com/MatteoGuadrini/PSCouchDB> [https://github.com/MatteoGuadrini/PSCouchDB]): using module PSCouchDB ... # Model exists??? New Database if (-not(Test-CouchDBDatabase -Database $Model -Authorization $Auth)) { New-CouchDBDatabase -Database $Model -Authorization $Auth -Partition } ... # A device detected: build doc $Data = New-Object -TypeName PSCouchDBDocument $Data.SetElement("device", @{}) $Data.SetElement("user", @{}) $Data.SetElement("site", @{}) ... $today = {0} ” -f (Get-Date -Format 'yyyyyMMdd') # Today device is contacted? $Device = Get-CouchDBDocument -Database $Model -Partition $today -Authorization $Auth -Info -ErrorAction SilentlyContinue if ($Device)) { Set-CouchDBDocument -Database test -Document "${today}:${Serial}" -Revision $Device._rev -Data $Data -Authorization $Auth } else { New-CouchDBDocument -Database test -Document $Serial -Data $Data -Authorization $Auth -Partition $today } ... This could be an example of a design that could be fine also in this case, if you identify a particular piece of data that unites users (employeeType ???) that could represent the database. then data within the document, you organize them as you want (you can also take a cue from my devices!) I hope I was helpful! I wish everyone a good day and ... long live rock'n'roll! Matteo Guadrini ________________________________ Da: Jan Lehnardt <j...@apache.org> Inviato: giovedì 8 aprile 2021 20:07 A: user@couchdb.apache.org <user@couchdb.apache.org> Oggetto: Re: Single vs user db's > On 8. Apr 2021, at 19:53, Olaf Krueger <okrue...@apache.org> wrote: > > >> Also, I don’t quite get what “re-creating” a database would entail. > > Sorry, it seems to me that doesn't makes sense. > While I wrote this I had the docs in my mind [1]: > >> If your use case creates lots of deleted documents (for example, if you are >> storing short-term data like >log entries, message queues, etc), you might >> want to periodically switch to a new database and >delete the old one (once >> the entries in it have all expired). > > But re-reading this it turns out to me that this only makes sense if we don't > need to keep the remaining docs. > >> Deleting a doc creates a tombstone, that’s where just deleting the user db >> is easier, you don’t want to collect too many tombstones. > > Just out of curiosity: > Would be the purge feature [2] a way out here? Yes, but it comes with other caveats. It is best used for “I accidentally committed a credit card number to CouchDB, let’s undo that” and less “clean up 1000s of old records every day” type of operations. It’ll work in a pinch, but if you are starting out, db-per-time allows you to avoid getting into a tight spot to begin with :) Best Jan — > > Thanks, > Olaf > > > [1] > https://docs.couchdb.org/en/stable/maintenance/performance.html#delete-operation > [2] https://docs.couchdb.org/en/latest/api/database/misc.html?highlight=purge