feathersjs-ecosystem / feathers-sync

Synchronize service events between Feathers application instances
MIT License
222 stars 41 forks source link

Async MongoClient.connect and app mixins #125

Closed PowerMogli closed 4 years ago

PowerMogli commented 5 years ago

In your docs it should be mentionded that if you are using a existing mongodb connection which is being instantiated when you configure your app it can happen that your services are not going to use the mixin of the adapters. Take a look at this code snippet:

.....
app.configure(mongodb);
app.configure(authentication);
app.configure(discovery);
app.configure(services);
app.configure(channels);
app.configure(chatInit);
app.use(express.errorHandler());

app.get('mongoClient').then(client => {
  app.configure(
    feathersSync.mongodb({
      db: client.db('sync'),
      collection: 'sync',
    }),
  );
});
....

feathers-sync gets the mongoClient when the connection to mongodb has been established but the services have already been configured and added to the router. This can lead to unexpected behaviour when you expect your services to be extended by the mongo adapter mixin.