v1.0.27
authoradam <anton@adamansky.com>
Fri, 14 Dec 2012 08:25:12 +0000 (15:25 +0700)
committeradam <anton@adamansky.com>
Fri, 14 Dec 2012 08:25:12 +0000 (15:25 +0700)
Changelog
package.json
tcejdb/bson.c
tcejdb/bson.h
tcejdb/ejdb.c

index 4f63ad3..aacfd19 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -1,6 +1,6 @@
 2012-12-14 Anton Adamansky. <adamansky@gmail.com>
     * Added `$addToSet` and `$pull` operations.
-    - Release 1.0.26
+    - Release 1.0.27
 
 2012-12-04 Anton Adamansky. <adamansky@gmail.com>
     * Allows multiple matching conditions for single query field. Eg: {'age' : {'$lt' : '60', '$gt' : '30'}}
index d15baef..30e1d70 100644 (file)
@@ -1,6 +1,6 @@
 {
     "name" : "ejdb",
-    "version" : "1.0.26",
+    "version" : "1.0.27",
     "main" : "node/ejdb.js",
     "description" : "EJDB - Embedded JSON Database engine",
     "homepage" : "http://ejdb.org",
index 1e73bd5..f91c111 100644 (file)
@@ -1557,6 +1557,33 @@ EJDB_EXPORT bson* bson_create_from_buffer2(bson *rv, const void* buf, int bufsz)
     return rv;
 }
 
+EJDB_EXPORT bool bson_find_merged_array_sets(const void *mbuf, const void *inbuf) {
+    assert(mbuf && inbuf);
+    bool found = false;
+    bson_iterator it, it2;
+    bson_type bt, bt2;
+    bson_iterator_from_buffer(&it, mbuf);
+    while ((bt = bson_iterator_next(&it)) != BSON_EOO) {
+        bson_iterator_from_buffer(&it2, inbuf);
+        bt2 = bson_find_fieldpath_value(bson_iterator_key(&it), &it2);
+        if (bt2 != BSON_ARRAY) {
+            continue;
+        }
+        bson_iterator sit;
+        bson_iterator_subiterator(&it2, &sit);
+        while ((bt2 = bson_iterator_next(&sit)) != BSON_EOO) {
+            if (!bson_compare_it_current(&sit, &it)) {
+                found = true;
+                break;
+            }
+        }
+        if (found) {
+            break;
+        }
+    }
+    return found;
+}
+
 EJDB_EXPORT bool bson_find_unmerged_array_sets(const void *mbuf, const void *inbuf) {
     assert(mbuf && inbuf);
     bool allfound = false;
index e041d57..da79dce 100644 (file)
@@ -1129,6 +1129,7 @@ EJDB_EXPORT bson* bson_create_from_buffer(const void *buf, int bufsz);
 EJDB_EXPORT bson* bson_create_from_buffer2(bson *bs, const void *buf, int bufsz);
 
 EJDB_EXPORT bool bson_find_unmerged_array_sets(const void *mbuf, const void *inbuf);
+EJDB_EXPORT bool bson_find_merged_array_sets(const void *mbuf, const void *inbuf);
 EJDB_EXPORT int bson_merge_array_sets(const void *mbuf, const void *inbuf, bool pull, bson *bsout);
 
 
index 5ae6b94..d6997d7 100644 (file)
@@ -1753,7 +1753,7 @@ static bool _qryupdate(EJCOLL *jcoll, const EJQ *ejq, void *bsbuf, int bsbufsz,
 
     if (pullqf) { //$pull
         char* inbuf = (bsout.finished) ? bsout.data : bsbuf;
-        if (!bson_find_unmerged_array_sets(bson_data(pullqf->updateobj), inbuf)) {
+        if (bson_find_merged_array_sets(bson_data(pullqf->updateobj), inbuf)) {
             if (bsout.finished) {
                 //reinit `bsout`, `inbuf` already points to `bsout.data` and will be freed later
                 bson_init_size(&bsout, bson_size(&bsout));