From: adam Date: Fri, 14 Dec 2012 05:31:21 +0000 (+0700) Subject: #11 X-Git-Tag: v1.2.12~573 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=749581c41f0e00c423ad054f6a556fd31fff19fb;p=platform%2Fupstream%2Fejdb.git #11 --- diff --git a/Changelog b/Changelog index f77806d..4f63ad3 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,7 @@ +2012-12-14 Anton Adamansky. + * Added `$addToSet` and `$pull` operations. + - Release 1.0.26 + 2012-12-04 Anton Adamansky. * Allows multiple matching conditions for single query field. Eg: {'age' : {'$lt' : '60', '$gt' : '30'}} - Release 1.0.25 diff --git a/README.md b/README.md index 9fa3dcb..cde7ec3 100644 --- a/README.md +++ b/README.md @@ -271,13 +271,19 @@ EJDB queries inspired by MongoDB (mongodb.org) and follows same philosophy. - {'name' : {'$icase' : {'$in' : ['tHéâtre - театр', 'heLLo WorlD']}}} For case insensitive matching you can create special type of string index. - Queries can be used to update records: - `$set` Field set operation. - - {some fields for selection, '$set' : {'field1' : {obj}, ..., 'field1' : {obj}}} - `$inc` Increment operation. Only number types are supported. - - {some fields for selection, '$inc' : {'field1' : number, ..., 'field1' : {number}} - `$dropall` In-place record removal operation. - - {some fields for selection, '$dropall' : true} + - Queries can be used to update records: + + $set Field set operation. + - {.., '$set' : {'field1' : val1, 'fieldN' : valN}} + $inc Increment operation. Only number types are supported. + - {.., '$inc' : {'field1' : number, ..., 'field1' : number} + $dropall In-place record removal operation. + - {.., '$dropall' : true} + $addToSet Atomically adds value to the array only if its not in the array already. + If containing array is missing it will be created. + - {.., '$addToSet' : {'json.field.path' : val1, 'json.field.pathN' : valN, ...}} + $pull - Atomically removes all occurrences of value from field, if field is an array. + - {.., '$pull' : {'json.field.path' : val1, 'json.field.pathN' : valN, ...}} NOTE: It is better to execute update queries with `$onlycount=true` hint flag or use the special `update()` method to avoid unnecessarily rows fetching. @@ -367,6 +373,11 @@ Convenient method to execute update queries. - {some fields for selection, '$inc' : {'field1' : number, ..., 'field1' : {number}} * `$dropall` In-place record removal operation. - {some fields for selection, '$dropall' : true} + * `$addToSet` Atomically adds value to the array only if its not in the array already. + If containing array is missing it will be created. + - {.., '$addToSet' : {'json.field.path' : val1, 'json.field.pathN' : valN, ...}} + * `$pull` Atomically removes all occurrences of value from field, if field is an array. + - {.., '$pull' : {'json.field.path' : val1, 'json.field.pathN' : valN, ...}} Call variations of update(): diff --git a/node/ejdb.js b/node/ejdb.js index c6a38b2..87ad3eb 100644 --- a/node/ejdb.js +++ b/node/ejdb.js @@ -202,14 +202,19 @@ EJDB.prototype.remove = function(cname, oid, cb) { * - {'name' : {'$icase' : {'$in' : ['tHéâtre - театр', 'heLLo WorlD']}}} * For case insensitive matching you can create special type of string index. * - * - Queries can be used to update records - * - * `$set` Field set operation. - * - {some fields for selection, '$set' : {'field1' : {obj}, ..., 'field1' : {obj}}} - * `$inc` Increment operation. Only number types are supported. - * - {some fields for selection, '$inc' : {'field1' : number, ..., 'field1' : {number}} - * `$dropall` In-place record removal operation. - * - {some fields for selection, '$dropall' : true} + * - Queries can be used to update records: + * + * $set Field set operation. + * - {.., '$set' : {'field1' : val1, 'fieldN' : valN}} + * $inc Increment operation. Only number types are supported. + * - {.., '$inc' : {'field1' : number, ..., 'field1' : number} + * $dropall In-place record removal operation. + * - {.., '$dropall' : true} + * $addToSet Atomically adds value to the array only if its not in the array already. + * If containing array is missing it will be created. + * - {.., '$addToSet' : {'json.field.path' : val1, 'json.field.pathN' : valN, ...}} + * $pull Atomically removes all occurrences of value from field, if field is an array. + * - {.., '$pull' : {'json.field.path' : val1, 'json.field.pathN' : valN, ...}} * * NOTE: It is better to execute update queries with `$onlycount=true` hint flag * or use the special `update()` method to avoid unnecessarily data fetching. diff --git a/tcejdb/ejdb.h b/tcejdb/ejdb.h index 4b19f2f..646af36 100644 --- a/tcejdb/ejdb.h +++ b/tcejdb/ejdb.h @@ -242,14 +242,19 @@ EJDB_EXPORT bson* ejdbloadbson(EJCOLL *coll, const bson_oid_t *oid); * - {'name' : {'$icase' : {'$in' : ['théâtre - театр', 'hello world']}}} * For case insensitive matching you can create special index of type: `JBIDXISTR` * - * - Queries can be used to update records + * - Queries can be used to update records: * - * `$set` Field set operation. - * - {some fields for selection, '$set' : {'field1' : {obj}, ..., 'field1' : {obj}}} - * `$inc` Increment operation. Only number types are supported. - * - {some fields for selection, '$inc' : {'field1' : number, ..., 'field1' : {number}} - * `$dropall` In-place record removal operation. - * - {some fields for selection, '$dropall' : true} + * $set Field set operation. + * - {.., '$set' : {'field1' : val1, 'fieldN' : valN}} + * $inc Increment operation. Only number types are supported. + * - {.., '$inc' : {'field1' : number, ..., 'field1' : number} + * $dropall In-place record removal operation. + * - {.., '$dropall' : true} + * $addToSet Atomically adds value to the array only if its not in the array already. + * If containing array is missing it will be created. + * - {.., '$addToSet' : {'json.field.path' : val1, 'json.field.pathN' : valN, ...}} + * $pull Atomically removes all occurrences of value from field, if field is an array. + * - {.., '$pull' : {'json.field.path' : val1, 'json.field.pathN' : valN, ...}} * * * NOTE: It is better to execute update queries with `JBQRYCOUNT` diff --git a/tcejdb/ejdb_private.h b/tcejdb/ejdb_private.h index 9fc2f26..700f8f4 100644 --- a/tcejdb/ejdb_private.h +++ b/tcejdb/ejdb_private.h @@ -56,7 +56,7 @@ enum { /**> Query field flags */ EJCONDSET = 1 << 10, /**> $set Set field update operation */ EJCONDINC = 1 << 11, /**> $inc Inc field update operation */ - EJCONDADDSET = 1 << 12, /**> $addToSet Adds value to the array only if its not in the array already */ + EJCONDADDSET = 1 << 12, /**> $addToSet Adds value to the array only if its not in the array already. */ EJCONDPULL = 1 << 13 /**> $pull Removes all occurrences of value from field, if field is an array */ };