Sails-ArangoJs

Sails-ArangoJs

  • Docs
  • API

›CRUD API

Getting Started

  • Installation
  • Creating Models
  • Testing

CRUD API

  • let
  • create
  • createEach
  • update
  • updateOne
  • upsert
  • find
  • findOne
  • sum
  • avg
  • destroy
  • count
  • aggregate
  • sample
  • findNear
  • findWithCount

Graph & Transactions

  • Implementing transacations
  • Graph

Going Native

  • Native Methods
  • Foxx Services

Finding Documents

findOne Method

The method used to get a single document in a collection given a criteria. The criteria is normally an index query eg. id field.

The criteria must be an object.

Usage

const updated = await User.findOne({
  id: "3787778",
});

// Do something with record;

The method returns a single document in object format or null if none was found.

Operators

Equal

The following example,

const user = await User.findOne({
  email: "angelow@gmail.com",
  password: "yyyy",
});

is equivalent to AQL

FOR u in user
    FILTER u.email=='angelow@gmail.com' AND password=='yyyy'
    return u;

Other Operators used in the find statement

The below operators can be combined just as they are used in the find statement.

OperatorMeaning
$gt>
$lt<
$gte>=
$lte<=
$ne!=
$inIN
$ninNOT IN
$likeLIke
$notlikeNOT LIke
$hasHAS
$betwenBETWEEN two values of an array

$has is used to query fields of Array<string> or Array<number> example {Roles:{$has:'Admin'}} will get users that has a role of Admin supposing the Roles field has a format of ['Admin', 'Owner' ...]

Selecting Attributes

Please refer the select method on how to specify the attributes you would like to return by specifying an array of attributes.

const documents = await Product.findOne({
  price: { $gt: 2000 },
})
  .limit(5)
  .select(["ProductName"]);
← findsum →
  • findOne Method
    • Usage
  • Operators
    • Equal
    • Other Operators used in the find statement
  • Selecting Attributes
Sails-ArangoJs
Docs
Getting StartedAPI Reference
Community
User ShowcaseStack OverflowTwitter
More
BlogGitHub
Cloudhub Developer Community
Copyright © 2022 Cloud Hub Limited