> For the complete documentation index, see [llms.txt](https://couchbase.shujuwajue.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://couchbase.shujuwajue.com/shi-yong-node-js-ke-hu-duan/ji-ben-cao-zuo/setji-he-fang-shi-cao-zuo.md).

# Set集合方式操作

> set集合的的特点：集合内不能有重复值

初始一个集合数据

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

Web UI 查看结果:

![](/files/-LfnTMr57CWQoygzPMFb)

## **集合中添加数据**

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

Web UI 查看结果:

![](/files/-LfnTMr7Hl29e49Ni1yw)

**注意：不能集合不能有重复的值，所以添加重复值会报错．**

## 判断集合中是否存在某值

```sql
bucket.setExists('name-set', "xiaowang", function(err, result) {
    if (err) throw err;
    console.log(result.value);
});
```

console结果:

```
true
```

## 获取集合大小

```javascript
bucket.setSize('name-set', function(err, result) {
    if (err) throw err;
    console.log(result.value);
});
```

console结果：

```
2
```

## 删除集合中的值

```javascript
bucket.setRemove('name-set', 'revin',function(err, result) {
    if (err) throw err;
    console.log(result.value);
});
```

Web UI 查看结果:

![](/files/-LfnTMr9mBWHmk6wRczA)
