title: MongoError when uploading a file using mongoose, gridfs-stream and multer
body: <p>I am running express 4 using <a href="https://github.com/expressjs/multer" rel="nofollow">multer</a>, <a href="https://github.com/aheckmann/gridfs-stream" rel="nofollow">gridfs-stream</a> and <a href="https://github.com/LearnBoost/mongoose" rel="nofollow">mongoose</a> with mongodb and I am attempting to upload a file and stream it to gridfs.</p>
  
  <p>The express route that does this is defined as:</p>
  
  <pre><code>app.post('/uploadfile', function (req, res) {
      console.dir(req.files);
  
      // The mongodb instance created when the mongoose.connection is opened
      var db = mongoose.connection.db;
  
      // The native mongo driver which is used by mongoose
      var mongoDriver = mongoose.mongo;
  
      // Create a gridfs-stream
      var gfs = new Gridfs(db, mongoDriver);
  
      var file = req.files.myFile;
  
      var fileId = new ObjectId();
  
      console.log("Creating WriteStream");
      var writeStream = gfs.createWriteStream({
          _id: fileId,
          filename: file.originalname,
          mode: 'w',
          content_type: file.mimetype,
          metadata: {
              id: '123',
              number: '2',
              name: "Kenny Erasmuson"
          }
       });
       console.log("Created WriteStream");
       req.pipe(writeStream);
       console.log("Finished!");
  });
  </code></pre>
  
  <p>Once the express app is running, a file is selected and uploaded (via an HTML multipart/form-data form), and the output from the node server is:</p>
  
  <pre><code>$ node server.js 
  Listening on port 8001
  { myFile: 
      { fieldname: 'myFile',
      originalname: 'kenny-credit-rating.pdf',
      name: '1082e5071ede1002c4ae5be6123226d8.pdf',
      encoding: '7bit',
      mimetype: 'application/pdf',
      path: 'uploads/1082e5071ede1002c4ae5be6123226d8.pdf',
      extension: 'pdf',
      size: 110782,
      truncated: false,
      buffer: null } 
  }
  Creating WriteStream
  Created WriteStream
  Finished!
  /Users/kenny/Dropbox/Dev/fileUploader/node_modules/mongoose/node_modules/mongodb/lib/mongodb/co nnection/base.js:246
      throw message;      
            ^
  MongoError: The dollar ($) prefixed field '$conditionalHandlers' in '_id.$conditionalHandlers' is not valid for storage.
  at Object.toError (/Users/kenny/Dropbox/Dev/fileUploader/node_modules/mongoose/node_modules/mongodb/lib/mongodb/utils.js:114:11)
  at /Users/kenny/Dropbox/Dev/fileUploader/node_modules/mongoose/node_modules/mongodb/lib/mongodb/collection/core.js:569:27
  at /Users/kenny/Dropbox/Dev/fileUploader/node_modules/mongoose/node_modules/mongodb/lib/mongodb/db.js:1157:7
  at /Users/kenny/Dropbox/Dev/fileUploader/node_modules/mongoose/node_modules/mongodb/lib/mongodb/db.js:1890:9
  at Server.Base._callHandler (/Users/kenny/Dropbox/Dev/fileUploader/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/base.js:448:41)
  at /Users/kenny/Dropbox/Dev/fileUploader/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:481:18
  at MongoReply.parseBody (/Users/kenny/Dropbox/Dev/fileUploader/node_modules/mongoose/node_modules/mongodb/lib/mongodb/responses/mongo_reply.js:68:5)
  at null.&lt;anonymous&gt; (/Users/kenny/Dropbox/Dev/fileUploader/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:439:20)
  at emit (events.js:95:17)
  at null.&lt;anonymous&gt; (/Users/kenny/Dropbox/Dev/fileUploader/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:201:13)
  </code></pre>
  
  <p>Has anyone any ideas what is causing the error and how to fix?</p>