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

Update

update Method

The method used to update one or more documents that meets a certain criteria

Usage

const updated = await User.update({
  email: "angelow@gmail.com"
})
  .set({ full_name: "Angela W. K.", password: "zzzzz" })
  .fetch();

// Do something with updated records.

.Fetch()

The .fetch() method will make sure that the method returns the updated records in an array format.

Filter Operators

OperatorMeaning
$gt>
$lt<
$gte>=
$lte<=
$ne!=
$inIN
$ninNOT IN
$likeLIke
$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' ...]

$lt Example

const students = await Student.update({
  age: { $lt: 15 }
}).set({
  AllowedAccess: true
});

$like Example

const students = await User.update({
  paid: true
}).set({
  AllowedAccess: true
});

The example above will update all records that starts with 'angela' in the email field.

Method Chaining vs Parameters Array

In the above examples, we have used method chaining tp update our documents. However, it is possible to use other methods. Example:

const students = await User.update(
  {
    paid: true
  },
  {
    AllowedAccess: true
  }
).fetch();

Other Data Manipulation Operators

The following are some of the implemented data manipulation operators update() and updateOne() methods.

OperatorOperation
$incIncrease or decrease a value
$incIncrease or decrease a value
$popRemove last item of array
$shiftRemove first item of array
$unshiftAdd Item in the front of an array
$unshiftsetAdd Item in the front of an array if it does not exist ih the array
$pushAdd Item at the end of an array
$pushsetAdd Item at the end of an array if it does not exist in the array
$pullRemove items from an array, accepts arrray

More examples

More examples of using this operator can be found in the updateOne method

← createEachupdateOne →
  • update Method
    • Usage
  • .Fetch()
    • Filter Operators
    • $lt Example
    • $like Example
  • Method Chaining vs Parameters Array
  • Other Data Manipulation Operators
  • More examples
Sails-ArangoJs
Docs
Getting StartedAPI Reference
Community
User ShowcaseStack OverflowTwitter
More
BlogGitHub
Cloudhub Developer Community
Copyright © 2022 Cloud Hub Limited