viewdb 0.5.5 → 0.5.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/observe.js
CHANGED
|
@@ -32,7 +32,7 @@ var Observer = function(query, queryOptions, collection, options) {
|
|
|
32
32
|
|
|
33
33
|
Observer.prototype.refresh = function(initial) {
|
|
34
34
|
var self = this;
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
this._collection._getDocuments(this._query, function(err, result) {
|
|
37
37
|
if(initial && self._options.init) {
|
|
38
38
|
self._cache = result;
|
|
@@ -42,7 +42,7 @@ Observer.prototype.refresh = function(initial) {
|
|
|
42
42
|
|
|
43
43
|
self._cache = merge(old, result, _.defaults({
|
|
44
44
|
comparatorId: function (a, b) {
|
|
45
|
-
|
|
45
|
+
return _.get(a, '_id') === _.get(b, '_id')
|
|
46
46
|
}
|
|
47
47
|
}, self._options));
|
|
48
48
|
//rewind cursor for next query...
|
|
@@ -50,4 +50,4 @@ Observer.prototype.refresh = function(initial) {
|
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
module.exports = Observer;
|
|
53
|
+
module.exports = Observer;
|
|
@@ -45,14 +45,20 @@ var ViewDBTimestampPlugin = function (viewDb) {
|
|
|
45
45
|
var oldFindAndModify = coll.findAndModify;
|
|
46
46
|
coll.findAndModify = function (query, sort, update, options, cb) {
|
|
47
47
|
var timestamp = new Date().valueOf();
|
|
48
|
-
var
|
|
48
|
+
var clonedUpdate = _.clone(update);
|
|
49
|
+
var setOnInsert = clonedUpdate.$setOnInsert || {};
|
|
49
50
|
setOnInsert.createDateTime = timestamp;
|
|
50
|
-
|
|
51
|
+
clonedUpdate.$setOnInsert = setOnInsert;
|
|
51
52
|
|
|
52
|
-
var set =
|
|
53
|
+
var set = clonedUpdate.$set || {};
|
|
53
54
|
set.changeDateTime = timestamp;
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
|
|
56
|
+
// if consumer tries to $set createDateTime it will lead to conflict. remove it
|
|
57
|
+
if (set.createDateTime) {
|
|
58
|
+
delete set.createDateTime;
|
|
59
|
+
}
|
|
60
|
+
clonedUpdate.$set = set;
|
|
61
|
+
oldFindAndModify.apply(this, [query, sort, clonedUpdate, options, cb]);
|
|
56
62
|
}
|
|
57
63
|
}
|
|
58
64
|
return coll;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "viewdb",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.10",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"directories": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"bluebird": "^2.9.30",
|
|
32
|
-
"kuery": "^0.
|
|
32
|
+
"kuery": "^0.5.2",
|
|
33
33
|
"lodash": "^4.13.1",
|
|
34
34
|
"node-uuid": "^1.4.3"
|
|
35
35
|
}
|