v1.10

Document

How to Start SequoiaDB

Basic Operation

Data Model

Database Management

Aggregation

Index

Replication

Cluster

Connector

Reference

Development

Release Note

FAQ

  • Content
  • Comments
  • History

Update

Of the basic database operations(i.e.CRUD), update operation are those that modify the existing records or documents in a collection, using update() method to modify documents in SequoiaDB.

Note:

All of the examples in this document use the sequoiadb shell interface.

update()

the update() method is the primary method used to modify documents in SequoiaDB, it has the following syntax:

db.collectionspace.collection.update(<rule>,[cond],[hint])

The corresponding opration in sql: the method of update is simalar with update...set statement :

. the [rule] parameter corresponds to set statement

. the [cond] parameter corresponds to where statement

. the [hint] parameter corresponds to the index name in index table

modify with update operator

If the update() method contains only rule parameter expression(such as the $set operator expression ), the update() method updates the corresponding fields in the document. To update fileds in the subdocuments, use dot notation(.).

  • update a field in a document

    use $set to update a value of a field. The following operation queries the bar collection for the document that has an _id field equal to 1 and sets the value of field first , in the subdocument name, to 'Mike':
    db.foo.bar.update({$set:{"name.first":"Mike"}},{_id:1})
    Note:

    if the rule parameter containas fields not in the current records, the update() method will add the new fields to the records.

  • remove a field from a record

    use $unset to remove the field from a record. The following operation queries the bar collection for all records where contains age field and remove the age filed, if a record doesn't contain the age field, skipping.
    db.foo.bar.update({$unset:{age:""}})
  • Update array

    if the update operation requires an update of an element in an array field, SequoiaDB use dot notation(.), array are zero-based. The following operation is to update second element in the arr array, it's value will increate 5:

    db.foo.bar.update({$inc:{"arr.1":5}})
  • hint parameter

    The following operation will traversal all the records through index, and update the value of field name to 'Tom', the name of index is 'textIndex'

    db.foo.bar.update({$set:{name:"Tom"}},null,{"":"textIndex"})
Note: more update operator
please login to comment.
Latest Comment
  • 2015-02-14

About Us

SequoiaDB is a financial-level distributed database vendor and is the first Chinese database listed in Gartner’s Magic Quadrant OPDBMS report. SequoiaDB has recently released version 3.0.
SequoiaDB is now penetrating the vertical sector Financial Industry quickly and had more than 50 banking clients and hundreds of enterprise customers in industries including government, telecommunication, Internet and IoT.

Beijing:
Tower R, No.8 North Star East Road, Chaoyang District, Beijing,China
Guangzhou:
Tower A, No.22 Qinglan Street, Panyu District, Guangzhou,China
Shenzhen:
Tsing Hua Tech Park, Nanshan District, Shenzhen,China
Tel:400-8038-339
E-mail:contact@sequoiadb.com