Data modeling - Migrating from mongoDb to couchbase

Hi Guys,

Recently I am facing a crazy problem, I want to migrate my banking system from MongoDB to couchbase
In mongodb I have 2 collection transactions and activity

The transactions collection contains _id , sourceUserId , destinationUserId , amount , tax ,… fields , And I shard it by _id

The activity collection , is a collection that depends on transactions , When I insert/update a document in transactions I insert/update 2 documents in activity

The activity collection contains _id , transactionId , userId , sourceUserId , destinationUserId , amount , tax ,… fields , And I shard it by userId

When user A send money to user B we have these 3 documents

transactions collection :
_id=1 , sourceUserId=A , destinationUserId=B , amount=100 , tax=0

activity collection :
_id=100 , transactionId=1 , userId=A , sourceUserId=A , destinationUserId=B , amount=100 , tax=0

_id=101 , transactionId=1 , userId=B , sourceUserId=A , destinationUserId=B , amount=100 , tax=0

transactions collection is only for internal usage and activity collection is for report to end user

So when user A need to fetch the transaction activities , I target a shard as actitity collection is sharded by userId

How can I migrate to couchbase?
As activity collection is duplicate data of transactions collection , Is it needed to migrate this collection? As there is no shard key in couchbase?

What is the best model design for couchbase?

1- Just migrate transactions and create two GSI on sourceUserId and destinationUserId , when user A need to fetch activities , I can run SELECT * FROM myBucket WHERE type="transaction" AND (sourceUserId="A" OR destinationUserId="A") , Is it good? As I have heavy read

2-I can create view (But I dont know how , and it is better that GSI approach?)

3-Can I have same data model as mongodb? 1 transaction + 2 activity document , How can I efficiently fetch user A activities

4-Is there any better ways?

Thnaks & Regards

this is not that kind of modeling.
Stan is a probabilistic programming language for the specification of statistical models.

Hi @camille_lola,

You’re welcome to ask on the Couchbase forums:

1 Like