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

Insert

In sequoiaDB, "create" means adding new document record into collections. We can add new record into collections through the method "insert". In sequoiaDB, the insert manipulations are as follow:
  • If there is no "_id" field in the document record which is about to be inserted, the client will automatically add "_id" field and insert an unique value.
  • If "_id" field is specified, the "_id" field in that collection should be unique, or exception will occur.
  • The maximum length of BSON document is 16MB.
  • The limits of fields are as follow:

    The field "_id" should be stored as primary key in a collection. The value of it should be unique and unchangable. The type of "_id" can be ordinary types except for array.

    The name of a field should not be null, start with "$" or contain (.).

Note: In this document, all examples use shell interface in sequoiadb.

insert()

The method insert() is used to insert record into insert records into sequoiaDB collection.The grammar of it is:

db.collectionspace.collection.insert(<doc|docs>,[flag])

Insert the first document

If there is no collection space and collection. Firstly, create collection (For example, "db.createCS("foo")" create collection space "foo") and collection (For example, "db.foo.createCL("bar")" create collection under collection space "bar"), then you are able to insert records.

db.foo.bar.insert(
  {
     _id:1,
     name:{fist:"Jhon",last:"Black"},
     phone:[1853742XXX,1802321XXX],
     remark:[
              {
                 position:"manager",
                 year:2000
                },
               {
                 position:"CEO",
                 year:2012
                }
             ]
  }
)

Users can check out whether the insert is successful through the method "find()"

db.foo.bar.find()

The result is as follow:

 {
    _id:1,
    name:{fist:"Jhon",last:"Black"},
    phone:[1853742XXX,1802321XXX],
    remark:[
       {
          position:"manager",
          year:2000
         },
        {
          position:"CEO",
          year:2012
         }
      ]
 } 

unspecified _id field

If a new document record doesn't conain "_id" field, the method insert() will add "_id" field into a document and generate an unique "$oid" value.

db.foo.bar.insert({name:"Tom",age:20})

This command insert a newe record into collection "bar". In the record, the value of "name" is "Tom". The value of "age" is 20. The "_id" field is unique:

{ "_id": { "$oid": "515152ba49af395200000000" }, "name": "Tom", "age": 20 }

Insert more than one record

If users insert an array document in the method "insert", the method "insert()" will execute batch inserts in a collection.

The following command inserts 2 records into collection "bar". This manipulation demonstrates the feature of dynamic mode in sequoiaDB. Although the record with "_id:20" contains field name "phone", but the other one doesn't contain that, sequoiaDB doesn't require all records to contains this field.

db.foo.bar.insert([{name:”Mike”,age:15},{_id:20,name:”John”,age:25,phone:123}])
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