简体   繁体   English

我可以在mongoose.js中为数组属性定义文档架构上的索引吗

[英]Can i define an index on doc schema for an array property in mongoose.js

I have the following Document Schema in mongoose2.4.8 running on node0.4.12: 我在node0.4.12上运行的mongoose2.4.8中具有以下文档架构:

var UserSchema = new Schema({
  following: [{type: ObjectId, ref: 'User'}],
  followers: [{type: ObjectId, ref: 'User'}]
});

I want to speed up the lookup in the these arrays. 我想加快这些数组中的查找。 Can i use mongoose.js index functionality? 我可以使用mongoose.js索引功能吗? And how? 如何?

Are you trying to lookup the ObjectId in the arrays? 您是否要在数组中查找ObjectId? Or are you looking for the User? 还是您在寻找用户? If the latter, add the index on the User Schema. 如果是后者,则在用户架构上添加索引。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM