Multiple data collections in Pouchdb
Asked Answered
S

1

5

In Pouchdb, what can be the best way to handle multiple data collections? I mean, for example, that instead of a simple to-do list, I need multiple to-do lists, like: home to-do, work to-do, community to-do, and ecology to-do.

Should I put it all inside one db and use one key in each doc to determine which list it belongs to? Or should I use different db's? In my app the user will be able to freely create and remove those data collections (or to-do lists, in the example).

Thank you, Marcio Moreira

Swingle answered 24/7, 2015 at 10:53 Comment(1)
I think you'd better have multiple DB's so that you can use indexes more efficiently.Rhubarb
F
8

You can add a "type" field to each document, or you can prefix the _id of the document (e.g. home_1, home_2, etc.). The advantage of the second strategy is that you don't need to create a secondary index, and can just use allDocs() to find e.g. all todos of type "home."

Fledge answered 24/7, 2015 at 12:33 Comment(2)
Thank you for your answer. Maybe this is a common question between people coming from a tabular world into Pouchdb. By the way, the pouchdb.com/guides are very well written. Congratulations.Symphonious
@nlawson, my app have two types of data: article data and user data. If I use the second strategy, I still need to separate them by the prefix 'article_xxx' or 'user_xxx' after using allDocs(). I think it is the same as the first approach of adding a 'type' field, and using query() to get the article data. Is it any other better approach to manage data in pouchDB, due to it lacking the collection like concept in mongoDB? Thx!Cantle

© 2022 - 2024 — McMap. All rights reserved.