# List链表方式操作

## list 链表操作

> 注意可以插入重复的数据

初始一个链表数据

```sql
bucket.upsert('name-list', ["revin"], function(err, result) {
    if (err) throw err;
    console.log(result);
});
```

Web UI 查看结果:

![](/files/-LfnTMk-g4INi3YtgVIm)

## 链表末尾加入数据

```sql
bucket.listAppend('name-list', "xiaoming", function(err, result) {
    if (err) throw err;
    console.log(result);
});
```

Web UI 查看结果:

![](/files/-LfnTMk1PDZtiX06IZJJ)

## 链表开头加入数据

```sql
bucket.listPrepend('name-list', "xiaozhang", function(err, result) {
    if (err) throw err;
    console.log(result);
});
```

Web UI 查看结果:

![](/files/-LfnTMk35sDdvO695WMJ)

## 获取链表中某个索引的值

```sql
bucket.listGet('name-list', 0, function(err, result) {
    if (err) throw err;
    console.log(result.value);
});
```

console结果

```
xiaozhang
```

## 获取链表的长度

```sql
bucket.listSize('name-list', function(err, result) {
    if (err) throw err;
    console.log(result.value);
});
```

console结果

```
3
```

## 修改链表索引位的值

```sql
bucket.listSet('name-list', 0 , "xiaowang" ,function(err, result) {
    if (err) throw err;
    console.log(result);
});
```

Web UI 查看结果:

![](/files/-LfnTMk5a6_nUsQZJ4pJ)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://couchbase.shujuwajue.com/shi-yong-node-js-ke-hu-duan/ji-ben-cao-zuo/list-lian-biao-cao-zuo.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
