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

Add an example for repository access #193

Open
igorshapiro opened this issue Oct 19, 2017 · 1 comment
Open

Add an example for repository access #193

igorshapiro opened this issue Oct 19, 2017 · 1 comment

Comments

@igorshapiro
Copy link
Contributor

async findByName(name) {
    const repository = await Q.Models.User.repository
    const collection = repository.adapter.client.collection('users')
    return collection.find({ name }).toArray()
  }
@ondrej-kvasnovsky
Copy link
Contributor

Because what I need, is mongo collection, I just injected mongo into my class, something like this.

module.exports = class {
  constructor(mongo) {
    this.mongo = mongo
  }

  async userCollection() {
    return this.mongo.collection('user')
  }
}```

I think this is more clear, better than through Q.Models

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

No branches or pull requests

2 participants