Skip to content

juona/mongoose-zonejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mongoose and Zone.js

A demonstration of how Mongoose does not work well with Zone.js

Workaround

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.

Usage

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:

  1. Without Zone.js, with the official driver.
  2. Without Zone.js, with Mongoose.
  3. With Zone.js, with the official driver.
  4. 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:UaFRNke93P7PzwXu@podbase-test-rhc1v.azure.mongodb.net/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:UaFRNke93P7PzwXu@podbase-test-rhc1v.azure.mongodb.net/test-mongoose?retryWrites=true&w=majority use-zone-js use-mongoose

About

A demonstration of how Mongoose does not work well with Zone.js

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published