开发者

Limiting embedded document size

I have user schema for MongooseJS with embedded document photos by PhotoSchema:

var UserSchema = new Schema({
    email    : { type : String, index : 'unique', set: toLower }
  , login    : { type : String, i开发者_开发技巧ndex : 'unique' }
  , password : { type : String } 
  , salt     : { type : String }
  , photos   : [ PhotoSchema ]
  , name     : { type : String }
});

When I retreive one user, how can I limit quantity of photos in result set?

Or should I retrive all photos that user have (even if there is a million)?


You can't retreive users with limited quantity of photos, but you can:

1.Load user(s) without photos first:

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

2.Load just user photos thats you need:

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

Documentation

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜