2011-06-15 95 views
3

我有PhotoSchemauser架构MongooseJS与嵌入文档photos限制内嵌文件大小

var UserSchema = new Schema({ 
    email : { type : String, index : 'unique', set: toLower } 
    , login : { type : String, index : 'unique' } 
    , password : { type : String } 
    , salt  : { type : String } 
    , photos : [ PhotoSchema ] 
    , name  : { type : String } 
}); 

当我retreive一个user,我怎么能限制的结果photos数量设置?

或者我应该检索用户拥有的所有照片(即使有一百万)?没有照片的第一

1.Load用户(S):

回答

6

你不能用的照片数量有限retreive的用户,但你可以

db.users.find({ _id: 1 }, { photos : 0 }); 

2.Load只是用户的照片。这是你需要:

db.users.find({}, {photos:{$slice: [20, 10]}}) // skip 20, limit 10 

Documentation