2 Solutions collect form web for “How does docker-compose link work?”

Containers will be reachable by their names. So, in your case, you have to use the name of the db service, which is db:

MongoClient.connect("mongodb://db:27017/mytest", function (err, db) {

Assuming your node.js application is your web service? Web can only access the db service by using the hostname db. However the rest service can access it using db or database because you have given it a link alias.

You can either replicate that links: alias in the web service definition, or change your connect string to use db instead of database.