I am not sure anyone can say, outside of generally, how you can do it without understanding your datacenter setup.
Generally speaking; this is going to be more of a network solution than a MongoDB solution. MongoDB supports this; as long as the clients can see the Mongo instances.
Pending the configuration of your datacenters and networks, you can host the clients within the same datacenters, on the same network, as the MongoDB cluster and the clients shall connect to the mongoS (routers). Unfortunately, speaking in generic terms like this is easier than the reality of specific datacenter and network configurations. There are a lot of considerations and possibilites pending the DC config.
Possible Setup
Let's say in DC 1 you have a client (A) and the following Mongo setup
- 2 config servers
- 2 mongoS
- 2 nodes for Shard-A (consisting of a replica set)
- 2 nodes for Shard-B (consisting of a replica set)
For argument's sake, let's say DC 1 is your primary DC and the MongoDB nodes in the RS will failover accordingly here by preference.
Then in DC 2 you have a client (B) and...
- a config server
- 1 mongoS
- 1 node for Shard-A
- 1 node for Shard-B
Either client in either DC can send WRITE requests to any of the MongoS instances. They will route the data to the appropriate shard. In this use case, they will of course WRITE the data to DC 1 which hosts the primary of each RS.
There are many ways to setup that Mongo cluster across multiple DCs. Technically for what you described, MOngoDB could be in one DC and you may just have clients across multiple DCs. You'll also want to consider network partitions, geography of the DCs, and failover preferences etc.
But you asked about Writes from either DC to Mongo. This is one (1) way of doing that and it presumes a lot without any other requirements for your use case. I can imagine someone else will have a very different suggestion and it is just as valid and accurate as this one.