mongoose-objectpath
v0.0.3
Published
mongoose Object 字段的增删改查
Downloads
5
Readme
mongoose Object 字段的增删改查
相关文章
http://qianduanblog.com/3323.html
安装
npm install mongoose-objectpath
API及说明
- 引用:
var mongooseObjectPath = require('mongoose-objectpath');
。 mongooseObjectPath
的初始化:mongooseObjectPath(Schema, path);
。
较完整例子
// 增1:单个
Meta.setMeta({
userId: userId,
}, 'key1', 'value1', function(e, ret) {
if (e) {
console.log('错误:');
console.log(e.message);
} else {
console.log('正确:');
console.log(ret);
}
});
// 增2:多个
var data = {};
data['key1'] = 'value11';
data['key2'] = 'value22';
data['key3'] = 'value33';
Meta.setMeta({
userId: userId,
}, data, function (e, ret) {
if (e) {
console.log('错误:');
console.log(e.message);
} else {
console.log('正确:');
console.log(ret);
}
});
// 改1:单个
Meta.setMeta({
userId: userId,
}, 'key1', 'value11-11', function(e, ret) {
if (e) {
console.log('错误:');
console.log(e.message);
} else {
console.log('正确:');
console.log(ret);
}
});
// 改2:多个
var data = {};
data['key1'] = 'value11-22';
data['key2'] = 'value11-22';
data['key3'] = 'value11-22';
Meta.setMeta({
userId: userId,
}, data, function(e, ret) {
if (e) {
console.log('错误:');
console.log(e.message);
} else {
console.log('正确:');
console.log(ret);
}
});
// 查1:所有
Meta.getMeta({
userId: userId,
}, function(e, ret) {
if (e) {
console.log('错误:');
console.log(e.message);
} else {
console.log('正确:');
console.log(ret);
}
});
// 查2:单个
Meta.getMeta({
userId: userId,
}, 'key2', function(e, ret) {
if (e) {
console.log('错误:');
console.log(e.message);
} else {
console.log('正确:');
console.log(ret);
}
});
// 查3:多个
Meta.getMeta({
userId: userId,
}, ['key1','key2'], function(e, ret) {
if (e) {
console.log('错误:');
console.log(e.message);
} else {
console.log('正确:');
console.log(ret);
}
});
// 删1:单个
Meta.removeMeta({
userId: userId,
}, 'key1', function(e, ret) {
if (e) {
console.log('错误:');
console.log(e.message);
} else {
console.log('正确:');
console.log(ret);
}
});
// 删2:多个
Meta.removeMeta({
userId: userId,
}, ['key1','key2','key3'], function(e, ret) {
if (e) {
console.log('错误:');
console.log(e.message);
} else {
console.log('正确:');
console.log(ret);
}
});
// 删3:所有
Meta.removeMeta({
userId: userId,
}, function(e, ret) {
if (e) {
console.log('错误:');
console.log(e.message);
} else {
console.log('正确:');
console.log(ret);
}
});