English 中文(简体)
是否可能从Mongoose的模型中仅提取嵌入式文件?
原标题:Is it possible to extract only embedded documents from a Model in Mongoose?

我愿就模式提出质询,但只有在问询与质相符的情况下,才有复方文件。 审议下列事项......

var EventSchema = new mongoose.Schema({
    typ : { type: String },
    meta : { type: String }
});

var DaySchema = new mongoose.Schema({
    uid: mongoose.Schema.ObjectId,
    events: [EventSchema],

    dateR: { type: Date,  default : Date.now }

});

function getem() {
    DayModel.find({events.typ :  magic }, function(err, days) {
         // magic. ideally this would return a list of events rather then days    
    });

}

That find operation will return a list of DayModel documents. But what I d really like is a list of EventSchemas alone. Is this possible?

最佳回答

不可能直接挑出事件目标,但你可以限制你问回哪类情况:

DayModel.find({events.typ :  magic }, [ events ], function(err, days) {
   ...
});

然而,你仍需要通过结果从问询所交回的文件中提取实际嵌入的领域。

问题回答

暂无回答




相关问题
Access DB Ref MongoDB

Whats the best way to access/query a DB Ref: UPDATE: users: name, groupref : {$ref:"groups",$id:"ObjectId ..." } } groups: name, topic, country,...,.. Assumption is that user belongs to only one ...

MongoDB nested sets

What re the best practices to store nested sets (like trees of comments) in MongoDB? I mean, every comment can have a parent comment and children-comments (answers). Storing them like this: { ...

MongoMapper and migrations

I m building a Rails application using MongoDB as the back-end and MongoMapper as the ORM tool. Suppose in version 1, I define the following model: class SomeModel include MongoMapper::Document ...

MongoDB takes long for indexing

I have the following setup: Mac Pro with 2 GB of RAM (yes, not that much) MongoDB 1.1.3 64-bit 8 million entries in a single collection index for one field (integer) wanted Calling .ensureIndex(...) ...

Storing and accessing large amounts of data

My application creates pieces of data that, in xml, would look like this: <resource url="someurl"> <term> <name>somename</name> <frequency>somenumber</...

热门标签