|
|
@ -148,6 +148,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
module.setObjectField = function(key, field, value, callback) {
|
|
|
|
module.setObjectField = function(key, field, value, callback) {
|
|
|
|
var data = {};
|
|
|
|
var data = {};
|
|
|
|
|
|
|
|
// if there is a '.' in the field name it inserts subdocument in mongo, replace '.'s with \uff0E
|
|
|
|
|
|
|
|
field = field.replace(/\./g, '\uff0E');
|
|
|
|
data[field] = value;
|
|
|
|
data[field] = value;
|
|
|
|
db.collection('objects').update({_key:key}, {$set:data}, {upsert:true, w: 1}, function(err, result) {
|
|
|
|
db.collection('objects').update({_key:key}, {$set:data}, {upsert:true, w: 1}, function(err, result) {
|
|
|
|
if(callback) {
|
|
|
|
if(callback) {
|
|
|
@ -185,7 +187,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
var _fields = {};
|
|
|
|
var _fields = {};
|
|
|
|
for(var i=0; i<fields.length; ++i) {
|
|
|
|
for(var i=0; i<fields.length; ++i) {
|
|
|
|
_fields[fields[i]] = 1;
|
|
|
|
_fields[fields[i].replace(/\./g, '\uff0E')] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
db.collection('objects').findOne({_key:key}, _fields, function(err, item) {
|
|
|
|
db.collection('objects').findOne({_key:key}, _fields, function(err, item) {
|
|
|
@ -229,6 +231,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
module.isObjectField = function(key, field, callback) {
|
|
|
|
module.isObjectField = function(key, field, callback) {
|
|
|
|
var data = {};
|
|
|
|
var data = {};
|
|
|
|
|
|
|
|
field = field.replace(/\./g, '\uff0E');
|
|
|
|
data[field] = '';
|
|
|
|
data[field] = '';
|
|
|
|
db.collection('objects').findOne({_key:key}, {fields:data}, function(err, item) {
|
|
|
|
db.collection('objects').findOne({_key:key}, {fields:data}, function(err, item) {
|
|
|
|
if(err) {
|
|
|
|
if(err) {
|
|
|
@ -241,6 +244,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
module.deleteObjectField = function(key, field, callback) {
|
|
|
|
module.deleteObjectField = function(key, field, callback) {
|
|
|
|
var data = {};
|
|
|
|
var data = {};
|
|
|
|
|
|
|
|
field = field.replace(/\./g, '\uff0E');
|
|
|
|
data[field] = "";
|
|
|
|
data[field] = "";
|
|
|
|
db.collection('objects').update({_key:key}, {$unset : data}, function(err, result) {
|
|
|
|
db.collection('objects').update({_key:key}, {$unset : data}, function(err, result) {
|
|
|
|
if(callback) {
|
|
|
|
if(callback) {
|
|
|
@ -259,6 +263,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
module.incrObjectFieldBy = function(key, field, value, callback) {
|
|
|
|
module.incrObjectFieldBy = function(key, field, value, callback) {
|
|
|
|
var data = {};
|
|
|
|
var data = {};
|
|
|
|
|
|
|
|
field = field.replace(/\./g, '\uff0E');
|
|
|
|
data[field] = value;
|
|
|
|
data[field] = value;
|
|
|
|
db.collection('objects').update({_key:key}, {$inc : data}, {upsert:true}, function(err, result) {
|
|
|
|
db.collection('objects').update({_key:key}, {$inc : data}, {upsert:true}, function(err, result) {
|
|
|
|
module.getObjectField(key, field, function(err, value) {
|
|
|
|
module.getObjectField(key, field, function(err, value) {
|
|
|
|