Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Collection.update giving server error

Trying to learn the Meteor framework as well as coffeescript/node all at once. Been working on a simple file upload program that utilizes onloadend. When the FileReader onloadend event function is called I try to determine if the file already exists and if so I update with the new file data and version.

The code works for insert but not update. Can someone help? I've posted to meteor-talk w/o an answer as I suspect its the weekend (when I do most of my experimentation).

Code snippet...

file_reader.onloadend = ((file_event) ->
     (event) ->
        f_filename = escape file_event.name
        version = 0
        f_record = null

        f_record = doc_repo.findOne { name: f_filename }

        if f_record && f_record.name
          doc_repo.update
            name: f_filename
            ,
            $set:
              version: 10
        else
          doc_repo.insert
            name: f_filename
            data: event.target.result
            version: 0
    )(file_obj)

Error

Exception while invoking method '/documents/update' TypeError: Cannot read property 'toBSON' of undefined
    at Function.calculateObjectSize (/usr/local/meteor/lib/node_modules/mongodb/node_modules/bson/lib/bson/bson.js:210:12)
    at BSON.calculateObjectSize (/usr/local/meteor/lib/node_modules/mongodb/node_modules/bson/lib/bson/bson.js:1463:15)
    at UpdateCommand.toBinary (/usr/local/meteor/lib/node_modules/mongodb/lib/mongodb/commands/update_command.js:67:20)
    at Connection.write (/usr/local/meteor/lib/node_modules/mongodb/lib/mongodb/connection/connection.js:138:40)
    at __executeInsertCommand (/usr/local/meteor/lib/node_modules/mongodb/lib/mongodb/db.js:1837:14)
    at Db._executeInsertCommand (/usr/local/meteor/lib/node_modules/mongodb/lib/mongodb/db.js:1912:7)
    at Collection.update (/usr/local/meteor/lib/node_modules/mongodb/lib/mongodb/collection.js:445:13)
    at app/packages/mongo-livedata/mongo_driver.js:178:16
    at Db.collection (/usr/local/meteor/lib/node_modules/mongodb/lib/mongodb/db.js:507:44)
    at _Mongo._withCollection (app/packages/mongo-livedata/mongo_driver.js:51:13)  
like image 458
Tom Avatar asked Sep 16 '26 11:09

Tom


1 Answers

It looks like Mongo is not getting the second parameter which it needs to do the update. So in regular JavaScript it's expecting this:

collection.update({..selector..}, { .. modifier });

So I'd try putting some curly brackets around the modifier object, like this:

doc_repo.update
  name: f_filename,
  {
    $set:
      version: 10
  }
like image 71
cmather Avatar answered Sep 19 '26 02:09

cmather



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!