Skip to content

Instantly share code, notes, and snippets.

@boxxxie
Created March 26, 2012 03:34
Show Gist options
  • Save boxxxie/2202673 to your computer and use it in GitHub Desktop.
Save boxxxie/2202673 to your computer and use it in GitHub Desktop.
why does $.couch.db().bulkSave not work?
function inject_script(string){
var x = document.createElement('script');
x.src = string
document.body.appendChild(x);
}
inject_script("http://documentcloud.github.com/underscore/underscore-min.js")
inject_script("https://raw.github.com/boxxxie/underscore_extended/master/underscore_extended_browser.js")
var _users_db = $.couch.db("_users");
_users_db
.allDocs(
{
include_docs:true,
success:function(resp){
var users = _.chain(resp.rows)
.pluck('doc')
.reject(function(doc){return /^_design/.test(doc._id)})
.value();
console.log(users)
var enabled_users = _.map(users,function(user){return _.extend(user,{enabled:true})});
console.log(enabled_users)
console.log(JSON.stringify(enabled_users))
_.each(enabled_users,function(user){_users_db.saveDoc(user)}) //works
//_users_db.bulkSave(enabled_users) //doesn't work
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment