Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to get moleculer-db mongoose working #21

Closed
nurdism opened this issue Apr 7, 2018 · 5 comments · May be fixed by ebarahona/moleculer-db#14 or ebarahona/moleculer-db#15
Closed

Unable to get moleculer-db mongoose working #21

nurdism opened this issue Apr 7, 2018 · 5 comments · May be fixed by ebarahona/moleculer-db#14 or ebarahona/moleculer-db#15

Comments

@nurdism
Copy link

nurdism commented Apr 7, 2018

I'm running a very simple service, and I just can't get it to work, it just stops after 'Connected successfully...', no errors, it just stops, and I can't for the life of me figure out what is going on. Here's my test repo any help would be much appreciated.

$ node -v
v9.11.1
$ npm -v
5.8.0
@icebob
Copy link
Member

icebob commented Apr 7, 2018

Thanks. It seems, that problem is that, npm keeps an own mongoose version for adapter. Therefore, your Model instance is not inherited from the adapter mongoose version. Currently I don't know why...

image

@icebob
Copy link
Member

icebob commented Apr 7, 2018

A workaround if you uses schema & modelName in Service schem instead of model because in this case you shouldn't require the mongoose lib.

It works:

module.exports = {
  name: "test",
  mixins: [DbService],
  adapter: new MongooseAdapter("mongodb://localhost/test"),
  schema: {
    title: { type: String },
    content: { type: String },
    votes: { type: Number, default: 0}
  },
  modelName: "test",
  afterConnected() {
      this.logger.info("Connected successfully...");
      return this.adapter.clear().then(() => {
          this.logger.info("Seed Posts collection...");
          return this.adapter.insertMany([
              { title: "1st post", content: "First post content.", votes: 3 },
              { title: "2nd post", content: "Labore eum veritatis ut.", votes: 8 },
              { title: "3rd post", content: "Rerum deleniti repellendus error ea.", votes: 0 },
              { title: "4th post", content: "Normal post content.", votes: 4 },
              { title: "5th post", content: "Voluptatum praesentium voluptatibus est nesciunt fugiat." }
          ]);
      });
  }
}

@nurdism
Copy link
Author

nurdism commented Apr 7, 2018

@icebob
Copy link
Member

icebob commented Apr 7, 2018

Yes, I will change it.

@icebob
Copy link
Member

icebob commented Apr 8, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants