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 One

updateOne Method

The method used to update One record in a collection that meets a certain criteria. Mostly the criteria is search by a primary key.

Usage

const updated = await User.updateOne({
  id: "3787778"
}).set({ full_name: "Angela W. K.", password: "zzzzz" });

// Do something with the record;

by default, the .fetch() method is passed. The method returns the updated record in an object format.

Update Operators

The following key words are implemented in the update/updateOne query

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

$pushset and $unshiftset Example

const comment = await Comment.updatedOne(
  { id: "c234123" },
  { replies: { $pushset: reply }, likes: { $unshiftset: user.id } }
);

The $pushset operator adds a reply to a comment's replies array if it doesn't already exist and also adds the user's id to the list of likes

$pull and $shift Example

const comment = await Comment.updateOne(
  { id: "c234123" },
  { replies: { $pull: [reply1, reply2] }, likes: { $shift: true } }

  //note that \$pull requires that items to pull be an array
);

$pull would would remove the specific replies irrespective of position in the array while $shift would remove the first user ID in the array.

← updateupsert →
  • updateOne Method
    • Usage
    • Update Operators
    • $pushset and $unshiftset Example
    • $pull and $shift Example
Sails-ArangoJs
Docs
Getting StartedAPI Reference
Community
User ShowcaseStack OverflowTwitter
More
BlogGitHub
Cloudhub Developer Community
Copyright © 2022 Cloud Hub Limited