Map方式操作(针对文档字段)

针对的是一个已经存在的Key操作字段.

准备一条数据

bucket.upsert('xiaozhang', {"age":18, "sex": "boy"}, function(err, result) {
    if (err) throw err;
    console.log(result);
});

Web UI 查看结果:

加入一个新字段

bucket.mapAdd('xiaozhang', "hobby","singing", function(err, result) {
    if (err) throw err;
    console.log(result);
});

Web UI 查看结果:

获取KEY文档的size

bucket.mapSize('xiaozhang', function(err, result) {
    if (err) throw err;
    console.log(result.value);
});

console的结果:

3

获取KEY文档的某字段的值

bucket.mapGet('xiaozhang', "age", function(err, result) {
    if (err) throw err;
    console.log(result.value);
});

console的结果:

18

删除KEY文档的某字段

bucket.mapRemove('xiaozhang', "age", function(err, result) {
    if (err) throw err;
    console.log(result);
});

Web UI 查看结果:

Last updated

Was this helpful?