Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Can you use mongoose and mongodb services together? #251

Closed
eddyystop opened this issue Jul 30, 2017 · 6 comments
Closed

Can you use mongoose and mongodb services together? #251

eddyystop opened this issue Jul 30, 2017 · 6 comments

Comments

@eddyystop
Copy link

eddyystop commented Jul 30, 2017

My test app worked with 2 nedb plus 2 mongoose services. That original test threw after I added a mongodb service with the generator.

The problem seems to be that app.get('mongooseClient') now returns undefined. That value was being set outside my code when the test app worked.

I commented out the require and app.configure for the new mongodb service in src/services/index.js. That should have brought the app back to the way it was. However I was surprised to still get the same error.

Can an app use a mongoose and mongodb service together?

Edit: I now see app.get('mongooseClient') is set in src/mongodb.js

@eddyystop
Copy link
Author

I reverted my code. Confirmed the test ran with only calls to the 2 mongoose collections. I then ran feathers generate service to add a mongoDB service. With no other changes, I reran the same test.

I got the same error as above.

@eddyystop
Copy link
Author

When you create a mongoose service, src/mongodb.js is

const mongoose = require('mongoose');
module.exports = function () {
  const app = this;
  mongoose.connect(app.get('mongodb'));
  mongoose.Promise = global.Promise;
  app.set('mongooseClient', mongoose);
};

When you add a mongodb service, its overridden with

const MongoClient = require('mongodb').MongoClient;
module.exports = function () {
  const app = this;
  const config = app.get('mongodb');
  const promise = MongoClient.connect(config);
  app.set('mongoClient', promise);
};

So the generator does not support mongoose and mongo db clients simultaniously.

@eddyystop
Copy link
Author

Just to confirm, the mongoose test run OK with the following. I assume the mongo will also.

'use strict';

const MongoClient = require('mongodb').MongoClient;
const mongoose = require('mongoose');

module.exports = function () {
  const app = this;
  const config = app.get('mongodb');
  
  const promise = MongoClient.connect(config);
  app.set('mongoClient', promise);
  
  mongoose.connect(config);
  mongoose.Promise = global.Promise;
  app.set('mongooseClient', mongoose);
};

@daffl
Copy link
Member

daffl commented Jul 30, 2017

This should be fixed already via #229. Did you have the latest version of feathers-cli?

@eddyystop
Copy link
Author

eddyystop commented Jul 30, 2017

The mongo test threw because the mongoDB setup does not wait for app.set('mongoClient', promise); to resolve.

This is really a separate issue so I created #253

@eddyystop
Copy link
Author

eddyystop commented Jul 30, 2017

Yup, the current feathers-cli handles this. Nice! Thanks.

@daffl daffl closed this as completed Aug 9, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants