marcello3d / node-mongolian

[project inactive] Mongolian DeadBeef is an awesome Mongo DB driver for node.js
https://groups.google.com/group/node-mongolian
zlib License
349 stars 50 forks source link

Mongolian adding fields to documents on insert? #94

Closed petersondrew closed 12 years ago

petersondrew commented 12 years ago

I'm noticing some odd behavior after switching from mongoose to mongolian. When saving a document, the document object in the insert callback looks just fine (looks just like the object I saved with the _id field added). However, in Mongo, there's an extra field tacked on to the end of my object called "gcd" and it looks like a javascript function definition. Any ideas?

So here's the document as I save it and as it's returned to me in the callback to collection.insert


{ path: '/Users/drew/Music/Downplay/A Day Without Gravity/03 Sleep.flac',
  title: 'Sleep',
  album: 'A Day Without Gravity',
  artist: [ 'Downplay' ],
  albumArtist: [ 'Downplay' ],
  year: '2007',
  track: 3,
  disk: 0,
  genre: [],
  albumArt: [],
  duration: 210,
  container: 'flac',
  codec: 'flac',
  bitrate: 1043,
  sampleRate: 44100,
  _id: { bytes: <Buffer 4f 5f 8a 89 00 00 00 4c 25 00 00 04> } }

And here's how it looks when running find from the mongo shell


{ "path" : "/Users/drew/Music/Downplay/A Day Without Gravity/03 Sleep.flac",
"title" : "Sleep",
"album" : "A Day Without Gravity",
"artist" : [ "Downplay" ],
"albumArtist" : [ "Downplay" ],
"year" : "2007",
"track" : 3,
"disk" : 0,
"genre" : [ ],
"albumArt" : [ ],
"duration" : 210,
"container" : "flac",
"codec" : "flac",
"bitrate" : 1043,
"sampleRate" : 44100,
"_id" : ObjectId("4f5f8a890000004c25000004"),
"gcd" : function cf__34__f_(a, b) {
    while (a != 0) {
        var z = b % a;
        b = a;
        a = z;
    }
    return b;
} }

Here's some system info

% uname -v
Darwin Kernel Version 11.3.0: Thu Jan 12 18:47:41 PST 2012; root:xnu-1699.24.23~1/RELEASE_X86_64
% node --version
v0.6.12
% npm list
├── coffee-script@1.2.0 
├─┬ mongolian@0.1.17 
│ ├─┬ buffalo@0.1.3 
│ │ └── tosource@0.1.1 
│ ├── taxman@0.1.1 
│ └── waiter@0.1.1 
% mongod --version
db version v2.0.3, pdfile version 4.5
Tue Mar 13 13:16:31 git version: 05bb8aa793660af8fce7e36b510ad48c27439697
marcello3d commented 12 years ago

This isn't something being added by Mongolian. Perhaps some code you have/are requiring is modifying Object.prototype?

What happens if you add any of these lines?

console.dir(objectToInsert)
console.dir(Object.prototype)
console.dir(objectToInsert.__proto__)

Also try grepping for gcd in your project folder.

petersondrew commented 12 years ago

Ah, you're right. Very sorry about that. Looks like fluent-ffmpeg is polluting Object.prototype.