Insert()
Inserts entities into a collection, returning the primary keys assigned to the new rows.
pub async fn insert(&self, request: InsertRequest) -> Result<InsertResponse>
Request Syntax
let request = InsertRequest::builder()
.collection_name("books")
.columns(vec![
FieldData::Int64 {
name: "id".into(),
values: vec![1, 2],
},
FieldData::FloatVector {
name: "vector".into(),
values: vec![vec![0.1, 0.2], vec![0.3, 0.4]],
},
])
.build()?;
REQUEST FIELDS:
database_name: Option<String>Name of the target database; uses the default database when empty.
collection_name: StringName of the collection to insert into. Required.
partition_name: StringName of the partition to insert into. Required.
columns: Vec<FieldData>Column-oriented field values, one
FieldDataentry per field, in row order. See FieldData.rows: Vec<EntityRow>Row-oriented entities as JSON objects.
columnsandrowscannot both be provided. See EntityRow.
RETURN TYPE:
Result
RETURNS:
The mutation result, including the assigned primary keys and per-row status. Returns an Error if the operation fails.
DmlResponse
ids() // -> &Ids
succeeded_indices() // -> &[u32]
failed_indices() // -> &[u32]
is_acknowledged() // -> bool
insert_count() // -> i64
delete_count() // -> i64
upsert_count() // -> i64
timestamp() // -> u64
METHODS:
ids()(&Ids) -The primary keys assigned to the mutated rows. See Ids.
succeeded_indices()(&[u32]) -The row indices that succeeded.
failed_indices()(&[u32]) -The row indices that failed.
is_acknowledged()(bool) -Whether the mutation was acknowledged by the server.
insert_count()(i64) -The number of rows inserted.
delete_count()(i64) -The number of rows deleted.
upsert_count()(i64) -The number of rows upserted.
timestamp()(u64) -The mutation timestamp.
Example
let request = InsertRequest::builder()
.collection_name("books")
.columns(vec![
FieldData::Int64 {
name: "id".into(),
values: vec![1, 2],
},
FieldData::FloatVector {
name: "vector".into(),
values: vec![vec![0.1, 0.2], vec![0.3, 0.4]],
},
])
.build()?;
let resp = client.insert(request).await?;