Skip to content

ormjs: Attributes #8

@OKNoah

Description

@OKNoah
User.find(
  { active: true },
  0,
  10,
  { $attributes: ['_id', 'name', 'email'] }
)

This will do

static async find (selector, skip = 0, limit = 100, options) {
    if (!selector) selector = {}
    limit = Math.min(Math.max(limit, 0), 100)
    selector._removed = false
    const cursor = await this._call('byExample', selector, {skip, limit})
    const documents = await cursor.all()
    return documents.map(document => {
      let doc = document
      if (options.$attributes) doc = _.pick(document, options.$attributes)
      return this._createModelByDocument(doc)
    })
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions