Mongodb 限制嵌入文档的大小
我有Mongodb 限制嵌入文档的大小,mongodb,node.js,mongoose,Mongodb,Node.js,Mongoose,我有PhotoSchema为MongooseJS嵌入文档photos的user模式: var UserSchema = new Schema({ email : { type : String, index : 'unique', set: toLower } , login : { type : String, index : 'unique' } , password : { type : String } , salt : { type : Str
PhotoSchema
为MongooseJS
嵌入文档photos
的user
模式:
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 }
});
当我检索一个用户
时,如何限制结果集中的照片
的数量
或者我应该检索用户拥有的所有照片(即使有一百万张)?您不能检索照片数量有限的用户,但您可以: 1.首先加载没有照片的用户:
db.users.find( { _id: 1 }, { photos : 0 } );
2.只加载您需要的用户照片:
db.users.find({}, {photos:{$slice: [20, 10]}}) // skip 20, limit 10