Mongodb realm with my own backend

Hi team,
As I understood that mongodb realm work as backend as a service, but I want to use my own backend as express js and frontend with react or any other and want to use realm as local database + mongodb as online database, can I use like this, if yes then how?
Like how whatsapp store our chat offline on our device and sync with online database while online.