~> mongo
|
MongoDB shell version: 2.4.3
|
connecting to: test
|
> db.blah.count() // new empty table
|
0
|
|
// native and non-native functions
|
> var native = "".trim
|
function trim() { [native code] }
|
> var nonNative = function() {print('hi')}
|
function () {print('hi')}
|
>
|
> // everything is cool for the nonNative function
|
> db.blah.insert({f:nonNative})
|
> db.blah.find()[0]
|
{
|
"_id" : ObjectId("517967ac68f5d75f0efedc26"),
|
"f" : function () {print('hi')}
|
}
|
>
|
|
// lets try and trick it with a native function (it saves fine, bombs on retrieval)
|
// note: src/mongo/shell/types.js:L592 thrown below is a "for (var k in obj)" construct. the native function property bombs this, it is not the source of the error
|
> db.blah.insert({f:native})
|
> db.blah.find()[1]
|
Thu Apr 25 17:28:54.386 JavaScript execution failed: SyntaxError: Unexpected identifier
|
Thu Apr 25 17:28:54.386 JavaScript execution failed: Error: 16722 JavaScript execution failed: SyntaxError: Unexpected identifier at src/mongo/shell/types.js:L592
|
|
// record is there, but the property f throws an exception in the shell
|
> db.blah.find()[1]._id
|
ObjectId("517967c368f5d75f0efedc27")
|
> db.blah.find()[1].f
|
Thu Apr 25 17:29:29.342 JavaScript execution failed: SyntaxError: Unexpected identifier
|
Thu Apr 25 17:29:29.342 JavaScript execution failed: Error: 16722 JavaScript execution failed: SyntaxError: Unexpected identifier
|
|
// zero still works
|
> db.blah.find()[0]
|
{
|
"_id" : ObjectId("517967ac68f5d75f0efedc26"),
|
"f" : function () {print('hi')}
|
}
|
|