A demonstration of how Mongoose does not work well with Zone.js
As a workaround to these problems you might get away with using a separate NodeJS process just for your ZoneJS stuff. In my case I only needed Angular's server-side rendering, which was quite simple to get working.
The basic idea is that you run your ZoneJS code in a separate process and communicate with that process via messages. Demo code (untested, replicated from my own project) can be found in the workaround
directory.
Run npm run test
and provide a mongo connection URL, e.g.:
npm run test mongodb://localhost:27017,localhost:27018,localhost:27019/my-db?replicaSet=rs0
The program accepts the following parameters:
use-zone-js
- load Zone.js at the beginning of the application (require("zone.js/dist/zone-node")
).use-mongoose
- use Mongoose to connect to MongoDB. If this parameter is skipped, the official MongoDB driver will be used.
Thus there are four possible ways to run this application:
- Without Zone.js, with the official driver.
- Without Zone.js, with Mongoose.
- With Zone.js, with the official driver.
- With Zone.js, with Mongoose (this is the scenario which does not always work).
There is a specific case when scenario #4 does not work - that's when I try to connect to an Atlas cluster.
For testing purposes I have created a user with access to a certain database in my test cluster:
test-user
UaFRNke93P7PzwXu
Use the following URL:
mongodb+srv://test-user:[email protected]/test-mongoose?retryWrites=true&w=majority
The scenario which does not work as expected is reproduced using this command:
npm run test mongodb+srv://test-user:[email protected]/test-mongoose?retryWrites=true&w=majority use-zone-js use-mongoose