我的答案是否定的,但我想我会检查一下。
如果我有一个引用另一个记录的记录,如下所示:
public class Account{
@id
ObjectId id;
long balance;
@Reference
Customer customer;
}
public class Customer{
@id
ObjectId id;
String name;
Address address
@indexed
long social;
}
我可以根据引用值创建索引吗?例如,如果我希望能够按社交索引我的帐户,以便我可以快速查找给定社交的所有帐户,我可以这样做吗?
最佳答案
如果你想这样做,你可以使用复合索引
http://docs.mongodb.org/manual/tutorial/create-a-compound-index/#index-create-compound-index
在您的情况下db.Account.ensureIndex( { customer.id: 1, customer.name: 1, .... } )
关于java - morphia:我可以在引用的字段上建立索引吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26371223/