2011-06-15 93 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