Skip to content
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

updateAll is not working properly #13

Closed
svlungade opened this issue Apr 12, 2016 · 6 comments
Closed

updateAll is not working properly #13

svlungade opened this issue Apr 12, 2016 · 6 comments

Comments

@svlungade
Copy link

When given an array as input for a field, we are getting TypeError k.match is not a function.

We cannot give primary id as where clause in input parameter.

Both the issues are for updateAll method

@flam312
Copy link

flam312 commented Apr 14, 2016

@svlungade can you give some more details as to what is in the array you are passing to the updateAll function?

The update all function works for me when passing in the following array:

User.updateAll( [ {'id': 1}, {'id': 2}, {'id': 3}, {'id': 4}], { 'updated' : true}, callback);

@svlungade
Copy link
Author

TestDocument.updateAll( {id: "1234"}, {email:

"abcd55@gmail.com"}, function(err, results) {
console.log ('result is',results);
return callback(err, results);
});

Where id is a primary key (_id) and the first json is the condition and second is the one to be updated

This is what we are trying to do

@flam312
Copy link

flam312 commented Apr 15, 2016

@svlungade what is the error you see if any when you try to call the above code? I'm not sure I understand where the TypeError k.match error is coming from.

@svlungade
Copy link
Author

@flam312 - Thank you for the quick replies :).
There are 2 issues, the first one is you can ignore for now ... type k.match one.

Second issue is ... when we are trying with the example given, we are getting blank results, nothing gets updated.

@flam312
Copy link

flam312 commented Apr 15, 2016

@svlungade
Odd, so if you print results they are blank? You should see something print out for results.
For example if the update is successful you should get the in the result the id that was updated and the revision id.

{
"id": "123",
"rev": "16-393d8b69b74af75b4b787d8ecaa76e11"
}

Or if the id does not exist then the results will return { count: 0}.
However, if you get a error then I would expect results to be blank. Do you get anything when printing err?

@tonyffrench
Copy link
Contributor

@svlungade

In your first example the where clause is invalid it must be an object, not an array. You should have received an error like so: { [Error: The where clause [{"id":1},{"id":2},{"id":3},{"id":4}] is not an object] statusCode: 400 } https://docs.strongloop.com/display/public/LB/Where+filter

In the second case, you should get a response say function(err, info) where info.count indicates the number of documents updated. This works fine for me. Given that your using numbers for your primary key its very likely a duplicate of #2, make sure your Cloudant version is {"couchdb":"Welcome","version":"1.0.2","cloudant_build":"2579"} or later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants