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

Cannot set indexes #6

Closed
OKNoah opened this issue Aug 30, 2017 · 0 comments
Closed

Cannot set indexes #6

OKNoah opened this issue Aug 30, 2017 · 0 comments

Comments

@OKNoah
Copy link
Owner

OKNoah commented Aug 30, 2017

This code does not seem to work as intended:

static async _getCollection () {
    if (this._collection) {  // always seems to be true
      return this._collection
    }

    const db = await this._getDatabase()
    const collection = db.collection(this.name)
    try {
      await collection.create()
      await this._setIndexes(collection)
    } catch (e) {
    }
    return this._collection = collection
  }

  static async _setIndexes (collection) {
    const schema = this._getSchema()
    for (const field of schema) {
      if (!field.options.index) continue

      const path = field.path.join('.')
      const unique = field.options.unique
      await collection.createHashIndex(path, {unique})
    }
  }
OKNoah added a commit that referenced this issue Aug 30, 2017
OKNoah added a commit that referenced this issue Sep 3, 2017
@OKNoah OKNoah closed this as completed in #7 Sep 3, 2017
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

1 participant