0
我有兩個蒙戈集合一個蒙戈集合:嗎啡:查詢有@Reference到另一個集合抽出時間
public class TransactionDetails {
private String TYPE="NA";
private Long TransactionDateInLong;
@Reference
List<AccountingTransaction> accountingTransactionList;
}
而且
public class AccountingTransaction{
//Fields here.
}
我想查詢「TransactionDetails」使用嗎啡集合框架來獲取引用的「AccountingTransaction」。
這裏是嗎啡的查詢方法:
public List<TransactionDetails> getTransactions(Long fromDateInLong, Long endDateInLong) {
Query<TransactionDetails> query = createQuery();
query.and(
query.criteria("TransactionDateInLong").lessThanOrEq(endDateInLong),
query.criteria("TransactionDateInLong").greaterThanOrEq(fromDateInLong)
);
query.and(
query.criteria("TYPE").equal("Income")
);
return query.retrievedFields(true, "accountingTransactionList").asList();
}
索引對於「TransactionDateInLong」和「類型」字段創建:
db.getCollection('TransactionDetails').createIndex({"TransactionDateInLong" : 1.0});
db.getCollection('TransactionDetails').createIndex({"TYPE" : "text"});
查詢花費了大量的時間,與指標創建。
獲取異常爲「在服務器上找不到光標」。
有沒有什麼改進?我錯過了什麼嗎?
鑑於TransactionDetails有幾個數字解讀。的AccountingTransaction(說最大10),我覺得最好是通過使用@Embedded記法嵌入AccountingTransaction,這樣我可以保存網絡調用。 –