Created
October 28, 2012 04:57
-
-
Save mfrobben/3967589 to your computer and use it in GitHub Desktop.
insert mongoose model to mongodb collection causes stack overflow.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*jshint asi: true globalstrict: true*/ | |
"use strict"; | |
/** | |
* 507 backend service | |
* Coded by Developer Hive at Terrarium Inc. | |
* Copyright (c) 2012 Terrarium Inc. | |
*/ | |
var async = require('async'), | |
mongo = require('mongodb'), | |
mongoose = require('mongoose'), | |
util = require('util'), | |
Schema = mongoose.Schema | |
var Foo = new Schema({ | |
}) | |
var FooModel = mongoose.model('Foo', Foo) | |
var db = null, | |
collection = null | |
var settings = { | |
uri: 'mongodb://localhost/testdb', | |
name: 'testdb', | |
host: 'localhost' | |
} | |
async.series({ | |
mongoConnect: function(callback) { | |
mongoose.connect(settings.uri, function(err) { | |
mongo.connect(settings.uri, {db:{safe:true}}, function(err, connectedDb) { | |
db = connectedDb | |
callback(err, connectedDb) | |
}) | |
}) | |
}, | |
createCollection: function(callback){ | |
db.createCollection("test", function(err, coll){ | |
collection = coll | |
callback() | |
}); | |
}, | |
testFooInsert: function(callback){ | |
var badfood = new FooModel() | |
//var badfood = new ObjectID() | |
console.log(util.inspect(badfood, true, null, true)); | |
debugger; | |
collection.insert(badfood, callback) | |
} | |
}, function(err) { | |
console.log(err) | |
console.log('exiting') | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ _id: 508cbb9ae2bf9a5c28000001 } | |
[RangeError: Maximum call stack size exceeded] | |
exiting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ _shardval: undefined, | |
_events: {}, | |
_doc: | |
{ _id: | |
{ _bsontype: 'ObjectID', | |
id: 'P¹Õ»i\'\u0000\u0000\u0001' } }, | |
_maxListeners: 0, | |
_validationError: undefined, | |
__version: undefined, | |
_pres: | |
{ save: | |
[ [Function], | |
[Function], | |
[Function] ] }, | |
_inserting: undefined, | |
_selected: undefined, | |
_removing: undefined, | |
errors: undefined, | |
_strictMode: true, | |
__getters: {}, | |
_activePaths: | |
{ states: { require: {}, modify: {}, init: {}, default: [Object] }, | |
paths: { _id: 'default' }, | |
stateNames: | |
[ 'require', | |
'modify', | |
'init', | |
'default' ] }, | |
isNew: true, | |
_saveError: undefined, | |
_adhocPaths: undefined, | |
__id: undefined, | |
save: [Function], | |
_posts: { save: [] } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ _shardval: undefined, | |
_events: {}, | |
_doc: | |
{ _id: | |
{ _bsontype: 'ObjectID', | |
id: 'P¹Õ»i\'\u0000\u0000\u0001' } }, | |
_maxListeners: 0, | |
_validationError: undefined, | |
__version: undefined, | |
_pres: | |
{ save: | |
[ [Function], | |
[Function], | |
[Function] ] }, | |
_inserting: undefined, | |
_selected: undefined, | |
_removing: undefined, | |
errors: undefined, | |
_strictMode: true, | |
__getters: {}, | |
_activePaths: | |
{ states: { require: {}, modify: {}, init: {}, default: [Object] }, | |
paths: { _id: 'default' }, | |
stateNames: | |
[ 'require', | |
'modify', | |
'init', | |
'default' ] }, | |
isNew: true, | |
_saveError: undefined, | |
_adhocPaths: undefined, | |
__id: undefined, | |
save: [Function], | |
_posts: { save: [] } } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment