Comments (16)
Definitely. I'll implement support for $push, $pop, $addToSet. I should be able to find the time to do it in the next few days, meanwhile I'll leave this open.
from nedb.
It's now done, and included in the latest published version (v0.7.7).
from nedb.
See the doc here : https://github.com/louischatriot/nedb#updating-documents
from nedb.
Just a thankyou for a superquick fix :)
from nedb.
and I'm back with a possible bug/issue - relating to empty arrays...
Just using $set to add an element which is [] works but you cannot add anything to that 'array' (the isArray test is failing as it's an Object, apparently?)
I created a $pullall method to help me test this (it's probably something we'll need at some point - along with $pull) and it seems the same problem happens when an array is 'emptied'.
So you can use $push or $addToSet to create and fill and array but I cannot figure any way to deal with 'emptying' it again (which seems a legit thing to do?)
from nedb.
You can empty an array using the $pop operator, but of course you have to do it element-by-element so using $set is more appropriate. The behaviour you describe is strange, could you copy paste some code that helps me reproduce it on my machine ?
from nedb.
I posted a reply but it seems to have been eaten by something.
Basically, if you create a document with a property which is an array - you cannot then use $pop etc. on that array
e.g.
db.insert({"key": "mykey", "tags": []})
or even
db.insert({"key": "mykey", "tags": ["a","b","c"]})
You cannot then
db.update({"key": "mykey"},{$addToSet: {"tags": "d"}})
it fails with 'not an array'
If you don't set the property on insert, you CAN then 'create' it using $addToSet or $push and it works AOK - but if you $pop everything it reverts into that state of "not being an array" again
A 'console.log(obj[field])' in the $addToSet function shows it to be an [object] at this point
from nedb.
I'll see if I can reproduce this and get back to you if I need a more specific code example.
from nedb.
I should add that I'm converting existing code within a node webkit application so it's hard to pull-out bits of code - I'll go look into creating some standalone node code (but I've not done that before so it might take me a while!)
Also - here's my $pullall function - you might want to add it or something like it (and a $pull would be nice!) :)
/**
- Remove all elements of an array
*/
lastStepModifierFunctions.$pullall = function (obj, field, value) {
if (!util.isArray(obj[field])) { throw "Can't $pullall from non-array values"; }
obj[field] = [];
};
from nedb.
Update: I can confirm this problem seems to be specific to node webkit - running my test script in regular (W7-64) node works fine - same script in node webkit fails...
Checking what I've got installed, I'm on node webkit 0.5.1 which is node 0.10.5 - wheras my local node.js install is the latest 0.10.11
So I guess it's something which has changed inbetween those releases and/or something being tampered-with by node webkit?
So I updated to nw 0.6.0 but that's still node 0.10.5 and still throws the same errors :(
So I removed node.js and installed the standalone 0.10.5 and that STILL works - so the problem is in node webkit somewhere...
So I Googled and it seems there may be an issue with using isArray and/or instanceOf Array within nw - and I suspect this may be the source of this issue but I'm not really sure where to start looking...???
from nedb.
and I've found and fixed the problem - in model.js line 116 (the deepcopy function) it says
if (obj instanceof Array) {
which should be
if (util.isArray(obj)) {
and then it all seems to work fine...
from nedb.
Good for me if you found the problem :) I thought I had removed all the obj instanceof Array ... I'll correct this tomorrow.
from nedb.
I started work on a $pull and $pullall function - this version of $pull only does straight string matching tho, in the ideal world it would use the full query matching capabilies but it's a BIT beyond my JS skills to see how you'd do that - perhaps, when you have a few mins, you might see your way to adding that?
My code is as follows...
/**
* Remove selected elements of an array
*/
lastStepModifierFunctions.$pull = function (obj, field, value) {
if (!util.isArray(obj[field])) { throw "Can't $pull from non-array values"; }
while (obj[field].indexOf(value) !== -1)
obj[field].splice(obj[field].indexOf(value),1);
};
/**
* Remove all elements of an array
*/
lastStepModifierFunctions.$pullall = function (obj, field, value) {
if (!util.isArray(obj[field])) { throw "Can't $pullall from non-array values"; }
obj[field] = [];
};
from nedb.
I just fixed this strange bug and published the new version (v0.7.9), thanks !
Concerning $pull and $pullAll, their effect is a bit different in MongoDB than what your code does: you can actually give a query and MongoDB removes the elements matching this query. See http://docs.mongodb.org/manual/reference/operator/pull/ and http://docs.mongodb.org/manual/reference/operator/pullAll/
I intend to support these operations, but this will be tracked in another issue so I'll close this one. Also, please tell me if you want to do it and submit a PR so that we don't work on the same stuff!
from nedb.
For reference - I wrote those purely to help me resolve the array issues
and I wasn't sure how to integrate your 'query' methods - they're
nice-to-haves but not essential at this point I think
On 21 June 2013 08:59, Louis Chatriot [email protected] wrote:
I just fixed this strange bug and published the new version (v0.7.9),
thanks !Concerning $pull and $pullAll, their effect is a bit different in MongoDB
than what your code does: you can actually give a query and MongoDB removes
the elements matching this query. See
http://docs.mongodb.org/manual/reference/operator/pull/ and
http://docs.mongodb.org/manual/reference/operator/pullAll/I intend to support these operations, but this will be tracked in another
issue so I'll close this one. Also, please tell me if you want to do it and
submit a PR so that we don't work on the same stuff!—
Reply to this email directly or view it on GitHubhttps://github.com//issues/27#issuecomment-19802911
.
from nedb.
Indeed, but I will still implement them to keep the same API as MongoDB. I should be done within a week or so (lot of other work to do !)
from nedb.
Related Issues (20)
- Replica & sharding
- Question: Is it possible to use promises with this lib. HOT 1
- NPM found 2 high severity vulnerabilities in NeDB, require manual review HOT 10
- NeDB datastore Model needs to be provided
- update the version of underscore dependence! HOT 1
- How to search multiple feilds' "$and"? HOT 4
- Add link to "official" fork HOT 8
- "this library is no longer maintained" HOT 7
- Insert doesn't take place immediately HOT 2
- How to catch abort if the capacity of storage is full??
- $setOnInsert is not work??????
- high vulnerabilities for this package HOT 2
- Error: Cannot create a string longer than 0x1fffffe8 characters HOT 1
- Please update dependency underscore HOT 4
- files
- Data Loss HOT 1
- Request to move repo under NW Userland
- PLEASE !!! Fork this project and create a new one HOT 1
- How to use expireAfterSeconds?
- i have a probleme to photo to nedb db HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nedb.