collection name must be a String

1,908 views
Skip to first unread message

Andrew Barr

unread,
Feb 7, 2013, 7:38:46 AM2/7/13
to mongoo...@googlegroups.com
I am using Mongoose with MongoHQ and when saving get an error 'collection name must be a String however I am not setting the collection name so Mongoose is using the name of the model by default. Any guidance would eb appreciated.

Thanks

Aaron Heckmann

unread,
Feb 7, 2013, 2:40:06 PM2/7/13
to mongoo...@googlegroups.com
version of mongoose?
can you post something we can use to reproduce?


On Thu, Feb 7, 2013 at 4:38 AM, Andrew Barr <andre...@gmail.com> wrote:
I am using Mongoose with MongoHQ and when saving get an error 'collection name must be a String however I am not setting the collection name so Mongoose is using the name of the model by default. Any guidance would eb appreciated.

Thanks

--
--
http://mongoosejs.com - docs
http://plugins.mongoosejs.com - plugins search
http://github.com/learnboost/mongoose - source code
 
You received this message because you are subscribed to the Google
Groups "Mongoose Node.JS ORM" group.
To post to this group, send email to mongoo...@googlegroups.com
To unsubscribe from this group, send email to
mongoose-orm...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/mongoose-orm?hl=en
---
You received this message because you are subscribed to the Google Groups "Mongoose Node.JS ODM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-orm...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Aaron


Aaron Heckmann

unread,
Feb 7, 2013, 2:40:23 PM2/7/13
to mongoo...@googlegroups.com
Is it only MongoHQ or does it behave the same locally as well?

Andrew Barr

unread,
Feb 7, 2013, 3:09:27 PM2/7/13
to mongoo...@googlegroups.com
I currently have this model defined:

auditlog.js

var mongoose = require('mongoose');

var schema = new mongoose.Schema({ 
    date: { type: Date, default: Date.now }, 
    user: 'string', 
    action: 'string'  
});

var AuditLog = mongoose.model('AuditLog', schema);
module.exports.AuditLog = AuditLog;

and in my app.js

var mongoose = require("mongoose);
mongoose.connect('mongodb://user:pass...@linus.mongohq.com:10055/db_name');
mongoose.model('AuditLog', require('./models/auditlog')).AuditLog;


I then try to use the AuditLog like:

AuditLog.save({ 
      user: 'User Name', action: 'Did something in the application' 
    });

I have not tested locally, I have just started playing with nodejs and am using Cloud9 IDE.

Thanks in advance.

Andrew

Andrew Barr

unread,
Feb 7, 2013, 5:54:24 PM2/7/13
to mongoo...@googlegroups.com
I worked this out .. user error: I was not creating the document from the model. Works now.

auditlog.js

var mongoose = require('mongoose');
var Schema = mongoose.Schema;
module.exports = function() {    
    var schema = new Schema({ 
        date: { type: Date, default: Date.now }, 
        user: 'string', 
        action: 'string'  
    }, { collection: 'log'});
    mongoose.model('AuditLog', schema);
};


app.js

var AuditLog = mongoose.model('AuditLog');
var logger = new AuditLog({ user: 'User name', action: 'This is an action'});
logger.save(function (err) {});


Thanks
Reply all
Reply to author
Forward
0 new messages