Ejemplo n.º 1
0
// Inserts an element at a given position within an array. The position should be
// specified as part of the path, e.g. path.to.array[3]
func (set *MutateInBuilder) ArrayInsert(path string, value interface{}) *MutateInBuilder {
	op := gocbcore.SubDocOp{
		Op:   gocbcore.SubDocOpArrayInsert,
		Path: path,
	}
	if multiVal, isMulti := value.(subDocMultiValue); isMulti {
		op.Value = multiVal
	} else {
		op.Value, _ = json.Marshal(value)
	}
	set.ops = append(set.ops, op)
	return set
}
Ejemplo n.º 2
0
// Adds an element to the end (i.e. right) of an array
func (set *MutateInBuilder) ArrayAppend(path string, value interface{}, createParents bool) *MutateInBuilder {
	op := gocbcore.SubDocOp{
		Op:   gocbcore.SubDocOpArrayPushLast,
		Path: path,
	}
	if multiVal, isMulti := value.(subDocMultiValue); isMulti {
		op.Value = multiVal
	} else {
		op.Value, _ = json.Marshal(value)
	}
	if createParents {
		op.Flags |= gocbcore.SubDocFlagMkDirP
	}
	set.ops = append(set.ops, op)
	return set
}