According to current MongoDB ReplicaSet architecture, you can't use a single Replica Set with some members having parts of the databases or collections.
However, if you have the requirement of replicating a single database or collection in real-time in another location, I ended up with following workaround:
- Use
directoryPerDB
to separate the desired database files (Create a new replica with this option enabled if you don't have this already)
- Copy the directory of desired database to the new location.
- Deploy a new ReplicaSet with this single database.
- Write a simple script and use Change Streams to perform the replication for you.
As I said, you will end up with another Replica Set dedicated for this database, but replication is done in real-time and both Replica Sets has the data in a consistent way (You have to perform your write operations on first ReplicaSet, though).