-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature suggestion .update function #143
Comments
Hi @lgandecki A comment on your current code: import {
default as clone
} from 'clone';
users.find(matchingQuery).exec().then(function (docs) {
docs.forEach(function (doc, index) {
const newDoc = clone({ ...doc._data }); // <- use the clone here
modify(newDoc, setQuery);
delete newDoc._rev;
delete newDoc._id;
Object.keys(newDoc).forEach((el) => {
doc[el] = newDoc[el];
});
doc.save()
});
}); |
Thanks! I finally had some time to try to tackle this, here is the effect: |
We should also add the update-function this to RxQuery, similar to RxQuery.remove await myCollection.find()
.where('age')
.gt(18)
.update({$set: {firstName: 'new first name'}}); |
Alright :) |
done! I also recreated the branch without changing dist files. |
Hi @lgandecki
it('unset a value', async() => {
const c = await humansCollection.createPrimary(1);
const doc = await c.findOne().exec();
console.dir(doc.firstName);
await doc.update({
$unset: {
firstName: ''
}
});
const updatedDoc = await c.findOne().exec();
assert.equal(updatedDoc.firstName, '');
});
// AssertionError: 'Darby' == ''
|
hey @pubkey Thansk for the feedback!
3/4) I guess the size is so big and it has some weird things like internal ejson, base64 etc because I wanted to keep it as much as possible in line with minimongo code, to allow easier updates. But, now when I think about, I won't need to keep it up to date with minimongo too much, as long as the modifyjs functionality work. I can refactor the whole code and make it much smaller. I will work on that and let you know. |
@pubkey At this point the npm run disc shows 11 kb added, but 3.7 kb of them are deepEqual and clone, the same ones you use in your project. Any ideas how to make rxdb use just one copy of them, instead of two? The pr is updated |
@lgandecki Sorry, I messed up your PR. it('unset a value', async() => {
const c = await humansCollection.createPrimary(1);
const query = c.find();
await query.update({
$unset: {
firstName: ''
}
});
const docs = await query.exec();
for (let doc of docs)
assert.equal(doc._data.firstName, undefined);
c.database.destroy();
}); |
TODO:
|
@pubkey I guess this was caused by my misunderstanding of how the .save() behaves. It is a bit weird that deleting the field directly from the RxDocument would work in some cases, but not in the others. Good thing you caught this :-) Also, I switched the unsetting to age, which isn't a required field on the "human" human schema. What's next? Do you want to split the remaining work? Not sure what you mean by "tests for each function with $set $unset" |
Hi @lgandecki thank you for the new PR. With the tests-task, I mean that for each of the 3 functions [ I will investigate about the |
@lgandecki I think the problem with the deepEqual/clone-import is, that your |
Ok, thanks! I will take a look at this and adding the tests tomorrow. |
@pubkey Working on the tests now.. |
Added the missing tests. Documentation and Changelog is missing, not sure if you prefer to change them yourself? :) |
@pubkey is there anything more I can do to help this get merged? |
@lgandecki sorry for not replying. I have this merge in mind for the last 7 days and everyday something came in between. |
Further changes by me:
|
Hello, I've been playing with this a bit, love it!
The functionality I'm missing is to do updates in a mongo update(matcher, changes) manner. I've built a simple solution for that stealing some code from minimongo. Would you be willing to take a PR? Or is a lack of update a design decision?
What I'm doing now is:
setQuery can be {$set: {}}, or use $rename, $pullAll $pop $push $unset etc.
modify changes the newDoc according to the setQuery.
I'm thinking of making the modify a standalone package, that would take a doc and return a new one, that could be a dependency in rxdb, and then I'd just add a simple update method. If not needed - not a problem! I will just polish it a bit for my own use :)
The text was updated successfully, but these errors were encountered: