开发者

Limiting embedded document size

开发者 https://www.devze.com 2023-03-13 14:52 出处:网络
I have user schema for MongooseJS with embedded document photos by PhotoSchema: var UserSchema = new Schema({

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

精彩评论

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

关注公众号