Re: [mongoose] Schema for compound _id field not supported?

559 views
Skip to first unread message

Aaron Heckmann

unread,
Jun 29, 2012, 3:45:24 PM6/29/12
to mongoo...@googlegroups.com
compound _id fields are not yet supported by mongoose.

you'll need to drop down to the driver for this.


On Fri, Jun 29, 2012 at 10:34 AM, Uli <m...@il.wolf-u.li> wrote:
Hello,

i'm trying to implement a hierarchical aggregation like here: http://docs.mongodb.org/manual/use-cases/hierarchical-aggregation/

For this i have managed the first M/R to build hourly data, but now i want to go further and i'm stuck with the model as it doesn't seem to work as expected.

The example for the hourly schema from the website translates (as i think) as follows to mongoose:
var DataHourlySchema = new Schema({
        _id
:        {
                       uid
: { type: String}
                     
, time : { type: Date}
                   
}
       
, value:    {
                       total
: {type : String, trim : true}
                     
, count : {type : String, trim : true}
                     
, mean : {type : String, trim : true}
                     
, ts : {type : Date}
                   
}
   
});

Unfortunately i cannot query on this schema using mongoose 2.7.1, e.g. count() returns 0 although i can see 87000 documents in another mongo browser which look like this:
{ "_id" : { "uid" : "testusername" , "time" : { "$date" : "2012-03-08T01:00:00.000Z"}} , "value" : { "total" : "28" , "count" : 5.0 , "mean" : "5.6" , "ts" : { "$date" : "2012-06-06T13:17:24.090Z"}}}

How can i access this data? Are compound _id-fields not supported? Or am i wrong somewhere?

Thanks in advance!

Best Regards,
Uli

--
http://mongoosejs.com
http://github.com/learnboost/mongoose
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



--
Aaron



Uli

unread,
Jun 30, 2012, 6:38:55 AM6/30/12
to mongoo...@googlegroups.com
Ok, thanks. But for this i cannot really use the Schema to ease operations then, tight?? I didn't go down to the driver yet, thus i'm not too familiar with it.

Thanks!

For more options, visit this group at
http://groups.google.com/group/mongoose-orm?hl=en

nwhite

unread,
Jun 30, 2012, 6:54:48 AM6/30/12
to mongoo...@googlegroups.com
Have you tried setting the options 'noId' and 'noVirtualId' to true on your schema and then using virtual paths?



Uli

unread,
Jul 2, 2012, 5:14:55 AM7/2/12
to mongoo...@googlegroups.com
So basically:

var mongoose = require('mongoose');
....
var opts = { noId: true, noVirtualId: true, strict: false }
DataHourlySchema = new Schema({}, opts);

var DataHourly = mongoose.model('DataHourly', DataHourlySchema);

I've taken a look at the lately added M/R-Support (https://github.com/LearnBoost/mongoose/pull/922) where it is more or less done like this. Although the model is directly returned, it gets defined in the same way (but some additional sugar like the lean-option). So i should be able to count using:

DataHourly.count(function (err, docs) {
    console
.log(docs);
});

Or not? Unfortunately i get a zero returned. I also tried to access the collection directly (as i do with M/R currently as well until Mongoose comes with M/R-Support), but had no luck there as well:
Dataloaderlogfilesynchourly.collection.count(function (err, docs) {
    console
.log(docs);
});

I also tried adding virtual paths, but i do not really succeed in getting them work. I think i have to get the data directly from the driver, but i after reading for a while i still don't know how to do that...:
DataHourlySchema.virtual('uid').get(function () {
   
return this.get('_id.uid');
});

Where did i skip a step?

Thanks in advance!
Reply all
Reply to author
Forward
0 new messages