Method: Moped::Query#first

Defined in:
lib/moped/query.rb

#firstHash Also known as: one

Get the first matching document.

Examples:

Get the first matching document.

db[:people].find.first

Returns:

  • (Hash)

    The first document that matches the selector.

Since:

  • 1.0.0



114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/moped/query.rb', line 114

def first
  reply = session.context.query(
    operation.database,
    operation.collection,
    operation.selector,
    fields: operation.fields,
    flags: operation.flags,
    skip: operation.skip,
    limit: -1
  )
  reply.documents.first
end