- v1.10
Document
Basic Operation
Data Model
Data Model Examples
Database Management
Database Management
Backup & Recovery
Aggregation
Replication
Replication Concept
Replication Operations
Reference
Cluster
Cluster Architecture
Cluster Deployment
Sharding
Connector
Reference
Development
C Driver
C++ Driver
C# Driver
Java Driver
PHP Driver
Python Driver
FAQ
- Content
- Comments
- History
Insert
- 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 (.).
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}])
- Latest Comment

2015-02-14