"SequoiaDB Giant Sequoia Database" insert() Overview 4

Example

Without specifying the _id field, insert a record.

db.sample.employee.insert( { name: "Tom", age: 20 } )

Insert a record with the _id field.

db.sample.employee.insert( {_id: 10, age: 20 } )

Insert multiple records, the following operation will insert two records in the collection employee.

db.sample.employee.insert( [ { _id: 20, name: "Mike", age: 15 }, { name: "John", age: 25, phone: 123 } ] )

Insert multiple records with duplicate "_id" keys, the following operation will insert two records in the collection employee

db.sample.employee.insert( [ { _id: 1, a: 1 }, { _id: 1, b:2 }, { _id: 3, c: 3 } ],  SDB_INSERT_CONTONDUP )
db.sample.employee.find()
{
  "_id": 1,
  "a": 1,
}
{
  "_id": 3,
  "c": 3
}

Insert a record and return the result as a Json object.

db.sample.employee.insert({a:1}, {ReturnOID:true, ContOnDup:true})
{
    "_id": {
        "$oid": "5becec3d6404b9295a63caca"
    }
    "InsertedNum": 1,
    "DuplicatedNum": 0
}
>
db.sample.employee.insert([{a:1}, {b:1}], {ReturnOID:true, ContOnDup:true})
{
    "_id": [
        {
            "$oid": "5bececdf6404b9295a63cacb"
        },
        {
            "$oid": "5bececdf6404b9295a63cacc"
        }
    ]
    "InsertedNum": 2,
    "DuplicatedNum": 0
}

Click on Jushan Database Documentation Center for more information

Guess you like

Origin blog.csdn.net/weixin_48909806/article/details/112941273