<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:syn="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/">
  <channel rdf:about="http://blog.gmane.org/gmane.comp.lang.javascript.mongoose">
    <title>gmane.comp.lang.javascript.mongoose</title>
    <link>http://blog.gmane.org/gmane.comp.lang.javascript.mongoose</link>
    <description/>
    <syn:updatePeriod>hourly</syn:updatePeriod>
    <syn:updateFrequency>1</syn:updateFrequency>
    <syn:updateBase>1901-01-01T00:00+00:00</syn:updateBase>
    <items>
      <rdf:Seq>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/636"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/635"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/634"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/633"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/632"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/631"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/630"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/629"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/628"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/627"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/626"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/625"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/624"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/623"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/622"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/621"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/620"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/619"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/618"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/617"/>
      </rdf:Seq>
    </items>
    <image rdf:resource="http://gmane.org/img/gmane-25t.png"/>
    <textinput rdf:resource=""/>
  </channel>
  <image rdf:about="http://gmane.org/img/gmane-25t.png">
    <title>Gmane</title>
    <url>http://gmane.org/img/gmane-25t.png</url>
    <link>http://gmane.org</link>
  </image>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/636">
    <title>Re: Re: Mongoose won't output Array in nested Schema</title>
    <link>http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/636</link>
    <description>&lt;pre&gt;are you referring to what is printed from console.log? if so it has a
default depth limit of 2. you can directly use util.inspect() to modify
that.

util.inspect(obj, showHidden, depth, colors)

http://nodejs.org/api/util.html#util_util_inspect_object_showhidden_depth_colors

On Tue, May 22, 2012 at 5:44 PM, pardoner &amp;lt;jonahwerre-Re5JQEeQqe8AvxtiuMwx3w&amp;lt; at &amp;gt;public.gmane.org&amp;gt; wrote:




&lt;/pre&gt;</description>
    <dc:creator>Aaron Heckmann</dc:creator>
    <dc:date>2012-05-23T12:46:57</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/635">
    <title>Re: Mongoose won't output Array in nested Schema</title>
    <link>http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/635</link>
    <description>&lt;pre&gt;var educationSchema = new Schema({
school: String
,major: String
,degree: {
type: String
, enum: ['diploma', 'certificate', 'AA', 'AS', 'BA', 'BS', 'MA',
'MS', 'PhD']
}
,start: Date
,end: Date
});




var employmentSchema = new Schema({
title: String
,start: Date
,end: Date
,employer: String
,city: String
});




var languageSchema = new Schema({
language: String
,proficiency: Number
});




var placeSchema = new Schema({
city: String
,country: String
});








var userSchema = new Schema({
first_name: String
,last_name: String
,email: {
type: String
,validate: /^[\w\.%\+\-]+&amp;lt; at &amp;gt;(?:[A-Z0-9\-]+\.)+(?:[A-Z]{2,6})$/i
// ,unique: true
}
,password: String
    ,gender: {
type: String
,enum: ['male', 'female']
,default: null
}
, city: String
, country: String
, birthday: Date
,type: {
type: String
,enum: ['guest', 'invitee', 'admin']
,default: 'guest'
}
,avatar: {
type: String
,validate: /^(((http|https):\/\/)?([[a-zA-Z0-9]\-\.])+(\.)([[a-zA-
Z0-9]]){2,4}([[a-zA-Z0-9]\/+=%&amp;amp;_\.~?\-]*))*$/
}
, skills: [String]
, interests : [String]
, bio : String
, lived : [placeSchema]
, visited : [placeSchema]
, languages: [ languageSchema ]
    , url: {
type: String
, validate: /^(((http|https):\/\/)?([[a-zA-Z0-9]\-\.])+(\.)([[a-zA-
Z0-9]]){2,4}([[a-zA-Z0-9]\/+=%&amp;amp;_\.~?\-]*))*$/
    }
, facebook: {
type: String
, validate: /^(((http|https):\/\/)?([[a-zA-Z0-9]\-\.])+(\.)([[a-zA-
Z0-9]]){2,4}([[a-zA-Z0-9]\/+=%&amp;amp;_\.~?\-]*))*$/
    }
, linkedin: {
type: String
, validate: /^(((http|https):\/\/)?([[a-zA-Z0-9]\-\.])+(\.)([[a-zA-
Z0-9]]){2,4}([[a-zA-Z0-9]\/+=%&amp;amp;_\.~?\-]*))*$/
    }
, twitter: {
type: String
, validate: /^(((http|https):\/\/)?([[a-zA-Z0-9]\-\.])+(\.)([[a-zA-
Z0-9]]){2,4}([[a-zA-Z0-9]\/+=%&amp;amp;_\.~?\-]*))*$/
    }
, employment: [ employmentSchema ]
, education: [ educationSchema ]
, profile : {
availability : {
to: Date
,from: Date
}
,value: Number
,field: {
type: String
, enum: ["management","development","technical","education"]
}
,country: Array
,industry : Array
,skills : Array
,goals : Array
,motivation : String
}
})

On May 20, 3:31 am, Aaron Heckmann &amp;lt;aaron.heckm...-Re5JQEeQqe8AvxtiuMwx3w&amp;lt; at &amp;gt;public.gmane.org&amp;gt; wrote:

&lt;/pre&gt;</description>
    <dc:creator>pardoner</dc:creator>
    <dc:date>2012-05-23T00:44:14</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/634">
    <title>Re: Mongoose won't output Array in nested Schema</title>
    <link>http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/634</link>
    <description>&lt;pre&gt;var educationSchema = new Schema({
school: String
, major: String
, degree: {
type: String
, enum: ['diploma', 'certificate', 'AA', 'AS', 'BA', 'BS', 'MA', 'MS', 
'PhD']
}
, start: Date
, end: Date
});

var employmentSchema = new Schema({
title: String
, start: Date
, end: Date
, employer: String
, city: String
});

var languageSchema = new Schema({
language: String
, proficiency: Number
});

var placeSchema = new Schema({
city: String
, country: String
});


var userSchema = new Schema({
first_name: String
, last_name: String
, email: {
type: String
, validate: /^[\w\.%\+\-]+&amp;lt; at &amp;gt;(?:[A-Z0-9\-]+\.)+(?:[A-Z]{2,6})$/i
// , unique: true
}
, password: String
    , gender: {
type: String
, enum: ['male', 'female']
, default: null
}
, city: String
, country: String
, birthday: Date
, type: {
type: String
, enum: ['guest', 'invitee', 'pro', 'admin']
, default: 'guest'
}
, avatar: {
type: String
, validate: 
/^(((http|https):\/\/)?([[a-zA-Z0-9]\-\.])+(\.)([[a-zA-Z0-9]]){2,4}([[a-zA-Z0-9]\/+=%&amp;amp;_\.~?\-]*))*$/
}
, skills: [String]
, interests : [String]
, bio : String
, lived : [placeSchema]
, visited : [placeSchema]
, languages: [ languageSchema ]
    , url: {
type: String
, validate: 
/^(((http|https):\/\/)?([[a-zA-Z0-9]\-\.])+(\.)([[a-zA-Z0-9]]){2,4}([[a-zA-Z0-9]\/+=%&amp;amp;_\.~?\-]*))*$/
    }
, facebook: {
type: String
, validate: 
/^(((http|https):\/\/)?([[a-zA-Z0-9]\-\.])+(\.)([[a-zA-Z0-9]]){2,4}([[a-zA-Z0-9]\/+=%&amp;amp;_\.~?\-]*))*$/
    }
, linkedin: {
type: String
, validate: 
/^(((http|https):\/\/)?([[a-zA-Z0-9]\-\.])+(\.)([[a-zA-Z0-9]]){2,4}([[a-zA-Z0-9]\/+=%&amp;amp;_\.~?\-]*))*$/
    }
, twitter: {
type: String
, validate: 
/^(((http|https):\/\/)?([[a-zA-Z0-9]\-\.])+(\.)([[a-zA-Z0-9]]){2,4}([[a-zA-Z0-9]\/+=%&amp;amp;_\.~?\-]*))*$/
    }
, employment: [ employmentSchema ]
, education: [ educationSchema ]
, profile : {
availability : {
to: Date
, from: Date
}
, value: Number
, field: {
type: String
, enum: ["management","development","technical","education"]
}
, country: Array
, industry : Array
, skills : Array
, goals : Array
, motivation : String 
}
})


On Sunday, May 20, 2012 3:31:16 AM UTC-7, Aaron Heckmann wrote:

&lt;/pre&gt;</description>
    <dc:creator>pardoner</dc:creator>
    <dc:date>2012-05-23T00:56:07</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/633">
    <title>Re: Save failing without error</title>
    <link>http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/633</link>
    <description>&lt;pre&gt;Calling save with no callback.

  doc.save()

or you have disabled the `safe` mode of your schema:

  new Schema({..}, { safe: false })

On Tue, May 22, 2012 at 6:09 AM, Kevin Smith &amp;lt;respectthecode-BUHhN+a2lJ4&amp;lt; at &amp;gt;public.gmane.org&amp;gt; wrote:




&lt;/pre&gt;</description>
    <dc:creator>Aaron Heckmann</dc:creator>
    <dc:date>2012-05-22T13:18:12</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/632">
    <title>Save failing without error</title>
    <link>http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/632</link>
    <description>&lt;pre&gt;I have a model with a `index: {unique: true}`. The index is working and 
preventing duplicates in the database but I don't get an error when the 
save fails. What could cause this?

&lt;/pre&gt;</description>
    <dc:creator>Kevin Smith</dc:creator>
    <dc:date>2012-05-22T13:09:37</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/631">
    <title>Re: dup key MongoError: E11000 when trying to do an upsert</title>
    <link>http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/631</link>
    <description>&lt;pre&gt;oh right, yeah sorry about that. Heres a gist with the two options:
https://gist.github.com/2764948

On Mon, May 21, 2012 at 2:11 PM, David Boon &amp;lt;david.boon-Re5JQEeQqe8AvxtiuMwx3w&amp;lt; at &amp;gt;public.gmane.org&amp;gt; wrote:




&lt;/pre&gt;</description>
    <dc:creator>Aaron Heckmann</dc:creator>
    <dc:date>2012-05-21T21:54:19</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/630">
    <title>Re: dup key MongoError: E11000 when trying to do an upsert</title>
    <link>http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/630</link>
    <description>&lt;pre&gt;
Thanks Aaron, this may be working, although I suspect you will not like it 
:-).  I used the "init" method as you described but that resulted in some 
odd behavior, all of the callbacks worked like it really saved but it never 
went to the database and wrote a document to my collection.  I added 
"org.isNew = true" and it does go to the database (with the downside of a 
isNew attribute in my document).  That worked for "new", then for modified 
or "edited documents" I added a call to "markModified(path)" and that 
caused my document to get updated.

Here's a snippet...I'm not proud of it :-)

         var org = new Org();
          org.init(req.body);
          if (!doc || doc === null) {
             org.isNew = true;
          }

          _.each(_.keys(org._activePaths.paths), function(a) {
            if (a != '_id' &amp;amp;&amp;amp;  a != 'isNew') org.markModified(a);
          });
          callback(null, org);


I haven't found a way yet to avoid writing the isNew to my collection. 
Seems like when I remove that line, the document doesn't get saved when 
creating new documents....

Thanks for the help, much appreciated!

-Dave
 
On Monday, May 21, 2012 11:25:02 AM UTC-4, Aaron Heckmann wrote:

&lt;/pre&gt;</description>
    <dc:creator>David Boon</dc:creator>
    <dc:date>2012-05-21T21:11:53</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/629">
    <title>Re: dup key MongoError: E11000 when trying to do an upsert</title>
    <link>http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/629</link>
    <description>&lt;pre&gt;The error occurs b/c the _id field has a unique index on it as well.
Using `new Thing(obj).save()` tells mongoose that this is a completely new
document and to send an insert command.
Mongoose assumes that you know what you're doing when passing your own id.

You have a few options on the 2.x branch

1) use Model.update() directly
2) create an instance followed by a call to init() passing your object and
then saving:

var submittedDoc = {
  '_id': '4fb846e3cfaa183b15000006'
  , 'name': 'David'
  , 'n_name': 'david'
  , 'other': 'other stuff'
};

var doc = new Thing;
doc.init(submittedDoc);
doc.save(callback);

The master branch has support for findAndModify which would be even better.


On Sun, May 20, 2012 at 12:28 PM, Victor Powell &amp;lt;vicapowell39-Re5JQEeQqe8AvxtiuMwx3w&amp;lt; at &amp;gt;public.gmane.org&amp;gt;wrote:




&lt;/pre&gt;</description>
    <dc:creator>Aaron Heckmann</dc:creator>
    <dc:date>2012-05-21T15:25:02</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/628">
    <title>Re: Creating a model interpretor</title>
    <link>http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/628</link>
    <description>&lt;pre&gt;Thanks for your help Victor. I've decided to scrap mongoose in favour of a
package that actually works with my app. It's a bit nicer to use as well.
Mongoose gets a bad wrap in the community for being bloated anyways.

Regards,

Dave

Sent from my iPhone

On 2012-05-21, at 10:01 AM, Victor Powell &amp;lt;me-Jn9/JELbptJBDLzU/O5InQ&amp;lt; at &amp;gt;public.gmane.org&amp;gt; wrote:

Dave, you have an application level bug. Namely, you're calling: new
mongoose.Schema(old_schema_fields) when you probably want to be calling new
mongoose.Schema(converted_fields);. I only found that out doing the same
isolation method i've shown you above. I said I wasn't going to debug your
code for you but I just have... Your application has other issues. Try and
isolate them the same way and come back when you've worked out your next
problem and have a specific question related to it.

- Vic


On Mon, May 21, 2012 at 9:49 AM, David Di Biase &amp;lt;dave.dibiase-Re5JQEeQqe8AvxtiuMwx3w&amp;lt; at &amp;gt;public.gmane.org&amp;gt;wrote:




&lt;/pre&gt;</description>
    <dc:creator>David Di Biase</dc:creator>
    <dc:date>2012-05-21T14:04:55</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/627">
    <title>Re: Creating a model interpretor</title>
    <link>http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/627</link>
    <description>&lt;pre&gt;Dave, you have an application level bug. Namely, you're calling: new
mongoose.Schema(old_schema_fields) when you probably want to be calling new
mongoose.Schema(converted_fields);. I only found that out doing the same
isolation method i've shown you above. I said I wasn't going to debug your
code for you but I just have... Your application has other issues. Try and
isolate them the same way and come back when you've worked out your next
problem and have a specific question related to it.

- Vic


On Mon, May 21, 2012 at 9:49 AM, David Di Biase &amp;lt;dave.dibiase-Re5JQEeQqe8AvxtiuMwx3w&amp;lt; at &amp;gt;public.gmane.org&amp;gt;wrote:




&lt;/pre&gt;</description>
    <dc:creator>Victor Powell</dc:creator>
    <dc:date>2012-05-21T14:01:10</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/626">
    <title>Re: Creating a model interpretor</title>
    <link>http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/626</link>
    <description>&lt;pre&gt;Change the line to:  

fields = new mongoose.Model(
model_name,
new mongoose.Schema(this.convert_fields(old_schema_fields))
);


or better yet simplify it to just this:

var old_schema_fields = {
       email : {
            type : String,
       },
};
fields = new mongoose.Model(
model_name,
new mongoose.Schema(old_schema_fields)
);


It still doesn't work. You're pointing holes in the wrong things.

Or even if I try this:

this.init = function() {

// Establish the database connection for this class
db = mongoose.connect(
'mongodb://localhost/test'
);

fields = new mongoose.Model(
model_name,
new mongoose.Schema({
       email : {
           type : String,
       },
})
);
}


It still doesn't work.  

&lt;/pre&gt;</description>
    <dc:creator>David Di Biase</dc:creator>
    <dc:date>2012-05-21T13:49:11</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/625">
    <title>Re: Creating a model interpretor</title>
    <link>http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/625</link>
    <description>&lt;pre&gt;Because what you thought was your old problem, isn't actually your problem
now, is it? you have a new one. so lets strip this problem down to is
basics slowly getting rid of all the stuff we don't need. Now the problem
code looks like this:


var mongoose = require('mongoose')
    , Schema = mongoose.Schema
    , db = mongoose.connect('mongodb://localhost/test');

var old_schema_fields = {
    "email" : {
        "type" : "VARCHAR",
        "value" : "200",
        "null" : false,
        "comments" : "Users email address (primary login identifier)"
    }
};

function convert_fields(fields) {
var converted_fields = {};
for (var i in fields) {
// lets only use the email field for now which is a String
converted_fields[i] = {type:String};
}
return converted_fields;
}
var converted_fields = convert_fields(old_schema_fields);
console.log(converted_fields);
var fields = mongoose.Model('User',new Schema(old_schema_fields));

now can you guess what the problem is?

On Mon, May 21, 2012 at 9:11 AM, David Di Biase &amp;lt;dave.dibiase-Re5JQEeQqe8AvxtiuMwx3w&amp;lt; at &amp;gt;public.gmane.org&amp;gt;wrote:




&lt;/pre&gt;</description>
    <dc:creator>Victor Powell</dc:creator>
    <dc:date>2012-05-21T13:41:05</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/624">
    <title>Re: Creating a model interpretor</title>
    <link>http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/624</link>
    <description>&lt;pre&gt;I don't understand what your point is. Yah it works in your super basic code example, it doesn't work in a the more complicated, however simple, application I've written. Are you insinuating that I'm using it incorrectly? I don't think I am and I've looked at the docs + example. I'm instantiating a Schema differently, using new mongoose.Schema and new mongoose.Model but aside from that my app uses Mongoose according to the example.  

All I'm doing is instantiating a function and passing in the schema object. I *am* using String, Number without the previous paths. I've been doing that for the past 2 emails. I've reattached the exact file I'm using. The reason I posted the question is because I've already simplified the code down to its basics, it works with some pretty basic code. As soon as I throw it into a more complicated use case, it fails like this and I'm not sure why.

So what I'm asking for is if someone, may kindly help me analyze the situation.  

&lt;/pre&gt;</description>
    <dc:creator>David Di Biase</dc:creator>
    <dc:date>2012-05-21T13:11:19</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/623">
    <title>Re: Creating a model interpretor</title>
    <link>http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/623</link>
    <description>&lt;pre&gt;Lol. Awesome! So that fixes your one problem, right?

On May 20, 2012, at 10:02 PM, David Di Biase &amp;lt;dave.dibiase-Re5JQEeQqe8AvxtiuMwx3w&amp;lt; at &amp;gt;public.gmane.org&amp;gt; wrote:

 Yes...

&lt;/pre&gt;</description>
    <dc:creator>Victor Powell</dc:creator>
    <dc:date>2012-05-21T04:14:23</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/622">
    <title>Re: Simple Unit Testing</title>
    <link>http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/622</link>
    <description>&lt;pre&gt;Slight modification to the unit test file to allow for multiple tests to 
run and so the database doesn't get destroyed too 
soon: /**********************************
 * Unit tests
 * File: test/unit/db.test.js
 *********************************/
var should = require('should'),
    db = require('./../../models/db'),
    conn;

function setUp() {
    conn = db.connectTo('localhost', 'test');
}

function tearDown() {
    // based on recommendation from: 
https://github.com/LearnBoost/mongoose/issues/330
    setTimeout( function () {
        dropDb(conn);
        conn.connection.close();
    }, 1000);
}

function createTest(callback) {
    return function (done, assert) {
        setUp();
        callback(function(onComplete) {
            onComplete = onComplete || function() {};
            done(onComplete);
            tearDown();
        }, assert);
    };
}
// based on 
https://groups.google.com/d/msg/mongoose-orm/bvdS3B_oNcM/Xalrd5xNi7QJ
function dropDb(db) {
    db.connection.db.executeDbCommand( {dropDatabase: 1}, function(err, 
result) {
        console.log(err);
        console.log(result);
    });
}

module.exports = {
    'Testing creating anonymous user': createTest(function (done, assert) {
        conn.models.User.createOrGetAnonymousUser(function(err, user) {
            should.not.exist(err);
            user.should.have.property('username', 'Anonymous');
//                user.should.have.property('role', 0);

            // call again to make sure it still works after user has 
already been added
            conn.models.User.createOrGetAnonymousUser(function(err, user) {
                should.not.exist(err);
                user.should.have.property('username', 'Anonymous');
//                user.should.have.property('role', 0);
                done();
            });
        });
    })
};

On Sunday, May 20, 2012 7:19:44 PM UTC-5, Michael Yagudaev wrote:

&lt;/pre&gt;</description>
    <dc:creator>Michael Yagudaev</dc:creator>
    <dc:date>2012-05-21T03:34:17</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/621">
    <title>Re: Creating a model interpretor</title>
    <link>http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/621</link>
    <description>&lt;pre&gt;Yes...  

&lt;/pre&gt;</description>
    <dc:creator>David Di Biase</dc:creator>
    <dc:date>2012-05-21T02:01:55</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/620">
    <title>Re: Creating a model interpretor</title>
    <link>http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/620</link>
    <description>&lt;pre&gt;Dave, everything's cool. I want to help. but more than just helping you
answer this question, I want to also help you get your future questions
answered. I dont mean to sound frustrated. I'm kind of new to answering
questions myself. I'm normally the one asking them! but I've gotten the
same sort of feedback from others that Im giving you. It'll help you be a
better programmer and help you solve your problems more quickly as well as
help others to anser your question. Understand that if you think there's an
issue with mongoose or there's something about mongoose you don't
understand, write up an example that demonstrates it. I shouldn't have to
fish through applications specific code or be doing this myself when it's
something you are perfectly capable of doing.
right? just give me only what i need to answer your question. Infact, most
people just wont even bother responding if your question isn't "kind" like
that.

Now, let me know. does the first example work for you but not the second?

// test1.js
// Doesn't throw an error
var mongoose = require("mongoose")
  , Schema = mongoose.Schema

mongoose.connect('mongodb://localhost/test',function(err){
  if(err) throw err;
  var MySchema = new Schema({
      title : {
        type : String
      }
    })
});

// test2.js
// Throws an error
var mongoose = require("mongoose")
  , Schema = mongoose.Schema

mongoose.connect('mongodb://localhost/test',function(err){
  if(err) throw err;
  var MySchema = new Schema({
      title : {
        type : Schema.Types.String
      }
    })
});

On Sun, May 20, 2012 at 8:30 PM, David Di Biase &amp;lt;dave.dibiase-Re5JQEeQqe8AvxtiuMwx3w&amp;lt; at &amp;gt;public.gmane.org&amp;gt;wrote:




&lt;/pre&gt;</description>
    <dc:creator>Victor Powell</dc:creator>
    <dc:date>2012-05-21T01:15:49</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/619">
    <title>Re: Creating a model interpretor</title>
    <link>http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/619</link>
    <description>&lt;pre&gt;If you replace that line with just String you get the same result. I opted to use the mongoose.Scheme.Types reference in desperation of finding a Type constant that wouldn't throw an error. So even if I do use your sample code, it still doesn't function as we expect it to.

Listen, I can understand that you must be frustrated by receiving a lot of bogus requests and questions, however I honestly think there's a problem here. I've looked high and low for a solution that's similar before posting here. I'm really at a brick wall here, your serious attention to the problem would really help me out. If it ends up just being because my application, I'd happily swallow my pride and say sorry.  

&lt;/pre&gt;</description>
    <dc:creator>David Di Biase</dc:creator>
    <dc:date>2012-05-21T00:30:09</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/618">
    <title>Re: Creating a model interpretor</title>
    <link>http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/618</link>
    <description>&lt;pre&gt;Okay, so you're question really is...

mongoose.connect('mongodb://localhost/test',function(err){
  if(err) throw err;
  var SomethingThatsNotAMongooseType = {}
    , MySchema = new Schema({
      foo : {
        type : String // why does this work
      }
     , bar : {
       type : mongoose.Schema.Types.String // but not this?
    })
});

That's because "mongoose.Schema.Types" is part of the private internals of
mongoose. Just use the "String" first example above. You can tell if
something is intended to be part of the internals of mongoose if in the
source it says "&amp;lt; at &amp;gt;api private" it its part of the public api it'll say "&amp;lt; at &amp;gt;api
public"

- Vic

On Sun, May 20, 2012 at 7:44 PM, David Di Biase &amp;lt;dave.dibiase-Re5JQEeQqe8AvxtiuMwx3w&amp;lt; at &amp;gt;public.gmane.org&amp;gt;wrote:




&lt;/pre&gt;</description>
    <dc:creator>Victor Powell</dc:creator>
    <dc:date>2012-05-21T00:20:49</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/617">
    <title>Re: Simple Unit Testing</title>
    <link>http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/617</link>
    <description>&lt;pre&gt;Ok after some playing around I found a simple solution for Mongoose unit 
testing with Expresso and should.js. Below is a complete solution:

/**********************************
 * Unit tests
 * File: test/unit/db.test.js
 *********************************/
var should = require('should'),
    db = require('./../../models/db'),
    conn;

function setUp() {
    conn = db.connectTo('localhost', 'test');
}

function tearDown() {
    // based on recommendation from: 
https://github.com/LearnBoost/mongoose/issues/330
    setTimeout( function () {
        dropDb(conn);
        conn.connection.close();
    }, 1000);
}

function createTest(callback) {
    return function (done, assert) {
        setUp();
        callback(done, assert);
        tearDown();
    };
}
// based on 
https://groups.google.com/d/msg/mongoose-orm/bvdS3B_oNcM/Xalrd5xNi7QJ
function dropDb(db) {
    db.connection.db.executeDbCommand( {dropDatabase: 1}, function(err, 
result) {
        console.log(err);
        console.log(result);
    });
}

module.exports = {
    'Testing creating anonymous user': createTest(function (done, assert) {
        conn.models.User.createOrGetAnonymousUser(function(err, user) {
            should.not.exist(err);
            user.should.have.property('username', 'Anonymous');

            // call again to make sure it still works after user has 
already been added
            conn.models.User.createOrGetAnonymousUser(function(err, user) {
                should.not.exist(err);
                user.should.have.property('username', 'Anonymous');
            });
        });
    })
};

/**********************************
 * code to be tested
 * File: models/db.js
 *********************************/
 var mongoose = require('mongoose'),
    config = require('../config'),
    Schema = mongoose.Schema,
    ObjectId = Schema.ObjectId,
    dbConnection = null,
    db = {},
    models = {};

/**
 * Connect to the database
 * &amp;lt; at &amp;gt;param host String The database host e.g. localhost
 * &amp;lt; at &amp;gt;param database String The database name e.g. snippet
 * &amp;lt; at &amp;gt;param username String [optional] The database username e.g. root
 * &amp;lt; at &amp;gt;param password String [optional] The database password
 * &amp;lt; at &amp;gt;param port Number [optional] The database port number e.g. 1234
 */
function connectTo(host, database, username, password, port) {
    //only create a new DB if it doesn't exist
    username = username || '';
    password = password || '';
    port = port ? ':' + port : '';

    var authenticationStr; // e.g. &amp;lt;user&amp;gt;:&amp;lt;password&amp;gt;

    if (username === '' &amp;amp;&amp;amp; password === '') {
        authenticationStr = '';
    } else {
        authenticationStr = username + ':' + password + '&amp;lt; at &amp;gt;';
    }

    // e.g. mongodb://&amp;lt;user&amp;gt;:&amp;lt;password&amp;gt;&amp;lt; at &amp;gt;&amp;lt;host&amp;gt;:&amp;lt;port&amp;gt;/&amp;lt;db&amp;gt; or 
'mongodb://localhost/SnippetSkyDB_Dev'
    var dbLocation = 'mongodb://' + authenticationStr + host + port + '/' + 
database;

    if (!dbConnection) {
        dbConnection = mongoose.createConnection(dbLocation);
        db = buildDB();
    }

    return db;
}

function buildDB() {

    var UserSchema = new Schema({
        username : { type: String, required: true, unique: true },
        password : { type: String, required: true },
        role : { type: Number, min: 0, max: 2, required: true },
        name : {
            first : { type: String, required: true },
            last  : { type: String, required: true }
        }
    });

        UserSchema.statics.createOrGetAnonymousUser = function 
createOrGetAnonymousUser(callback) {
        callback = callback || function() {};
        this.find({ role:0 }, function (err, users) {
            if (err) {
                console.log('Error: Failed to find anonymous user');
                callback(err, users);
                return;
            }

            var count = users.length;
            if (count === 0) {
                var anonymousUser = new models.User({
                    username : 'Anonymous',
                    password : 'password',
                    email: 'noemail-hcDgGtZH8xNBDgjK7y7TUQ&amp;lt; at &amp;gt;public.gmane.org',
                    role : 0,
                    name : {
                        first : 'Anonymous',
                        last : 'Anonymous'
                    }
                });

                anonymousUser.save(function (err) {
                    if (err) {
                        console.log('Failed to create anonymous user:\n' + 
err.message);
                        callback(err, users);
                        return;
                    }
                    callback(err, anonymousUser);
                    console.log('Successfully created anonymous user');
                });
            } else if (count === 1) {
                callback(err, users[0]);
            } else if (count &amp;gt; 1) {
                console.log('Why do we have %d Anonymous users?', count);
                callback(new Error('Cannot have more than one anonymous 
user, seriously dude!'));
            }
        });
    };

    // register models
    models.User = dbConnection.model('User', UserSchema);

    /**** Build and "export" DB object ****/
    db.models = models;
    db.connection = dbConnection;

    return db;
}

module.exports.connectTo = connectTo;

On Sunday, May 20, 2012 4:54:48 PM UTC-5, Michael Yagudaev wrote:

&lt;/pre&gt;</description>
    <dc:creator>Michael Yagudaev</dc:creator>
    <dc:date>2012-05-21T00:19:44</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/616">
    <title>Re: Creating a model interpretor</title>
    <link>http://permalink.gmane.org/gmane.comp.lang.javascript.mongoose/616</link>
    <description>&lt;pre&gt;If you simply remove that line it won't err. The types are coming from Mongoose itself: mongoose.Schema.Types['Number']; so I can't see why it would be a problem.

When I log the converted structure I can see it's sending the correct type:

{
    email: {
        required: true,
        type: [Function: SchemaString]
    },
    first_name: {
        required: true,
        type: [Function: SchemaString]
    },
    last_name: {
        required: true,
        type: [Function: SchemaString]
    },
    password: {
        required: true,
        type: [Function: SchemaString]
    },
    status: {
    default:
        'test', enum: ['active', 'inactive']
    },
    created_at: {
    default:
        [Function: now], type: [Function: SchemaDate]
    },
    updated_at: {
        type: [Function: SchemaDate]
    },
    last_login: {
        type: [Function: SchemaDate]
    }
}​  

I'm really scratching my head on this one :(

&lt;/pre&gt;</description>
    <dc:creator>David Di Biase</dc:creator>
    <dc:date>2012-05-20T23:44:55</dc:date>
  </item>
  <textinput rdf:about="http://search.gmane.org/?group=$group=gmane.comp.lang.javascript.mongoose">
    <title>Search Engine</title>
    <description>Search the mailing list at Gmane</description>
    <name>query</name>
    <link>http://search.gmane.org/?group=$group=gmane.comp.lang.javascript.mongoose</link>
  </textinput>
</rdf:RDF>

