Couchbase Foreign keys

63 views
Skip to first unread message

Anderson Scherdovski

unread,
Dec 12, 2017, 11:37:36 AM12/12/17
to Couchbase Mobile
I have a bank with several foreign keys ... in the couchbase I'm going to be able to do Join or Filters? because I will need to make several filters ..
banco.png

Jens Alfke

unread,
Dec 12, 2017, 2:04:10 PM12/12/17
to mobile-c...@googlegroups.com
FYI, since it looks like you’re using some kind of relational db modeling tool — document databases aren’t like relational databases, and in particular it’s often a bad idea to fully normalize your data. So I don’t recommend designing your database as though it were relational.

One common design: if you have a one-to-many relationship where the ‘many’ records are small, it often makes sense to store them inline in an array. For example, store phone numbers as an array of strings (or dictionaries containing strings) in the contact/customer document, instead of making a separate document for each phone number.

Also note that in a fully distributed system you don’t have transactions, rather it’s more “eventual consistency”. So there can be moments where one document has been updated but not another that it relates to, making the data inconsistent. You need to be flexible about handling this, or if the data must always be consistent, store it in a single document (since docs are updated atomically.)

—Jens
Message has been deleted

Anderson Scherdovski

unread,
Dec 12, 2017, 2:31:39 PM12/12/17
to Couchbase Mobile
is that I made the application with sqlite more because of the synchronization I need to change to the CouchBase, so I have the relational model, but I know how the desktop works ... more my question is if I can make filters between several documents?thank you...

Priya Rajagopal

unread,
Dec 12, 2017, 2:45:48 PM12/12/17
to Couchbase Mobile
As mentioned by Jens earlier, since you are now working with Couchbase which is a NoSQL database , you should re-think the way your data is modeled. I understand that you were previously using a relational db and hence your data was modeled as such. But trying to retrofit a relational data model to use with a NoSQL db isn't really recommended. 

I am still not clear on "filters" (maybe you can give an example) but you can take a look at this blog for a preview of the kind of querying that is possible in Couchbase Lite 2.0.  There are JOINS and queries on collections as well which isn't discussed there but it should be a good starting point. 

This illustrates the data modeling concepts that Jens pointed out earlier

Jens Alfke

unread,
Dec 12, 2017, 6:19:05 PM12/12/17
to mobile-c...@googlegroups.com


On Dec 12, 2017, at 11:31 AM, Anderson Scherdovski <aandersons...@gmail.com> wrote:

more my question is if I can make filters between several documents?thank you…

I don’t know what you mean by “filters”. Please give more detail.

—Jens

Jens Alfke — Mobile Architect — Couchbase, Inc.

Anderson Scherdovski

unread,
Dec 13, 2017, 5:46:41 AM12/13/17
to Couchbase Mobile
for example if I have multiple addresses and I want to filter by state is it possible?
 
cliente = {
      '_id': ObjectID ('123456789abcdef'),
      'first_name': 'Arnold',
      'último nome': 'Pettibone',

      'endereços': [
        'casa' : {
          'rua': '1234 rua falsa',
          'cidade': 'Anytown',
          'estado': 'OH',
          'zip': '12345'
        },
        'trabalhos' : {
          'rua': '742 Evergreen Terrace',
          'cidade': 'Springfield',
          'estado': 'OH',
          'zip': '12345'
        }
      ]
 }

Jens Alfke

unread,
Dec 13, 2017, 1:42:27 PM12/13/17
to mobile-c...@googlegroups.com

On Dec 13, 2017, at 2:46 AM, Anderson Scherdovski <aandersons...@gmail.com> wrote:

for example if I have multiple addresses and I want to filter by state is it possible?

Yes. Please read the documentation on views and queries in Couchbase Lite.

—Jens
Reply all
Reply to author
Forward
0 new messages