2017-05-05 6 views
2

VoyageMongoクエリの戻り値フィールドを制限する可能性を探しています。 フィールド(personId、firstName、lastName)を持つdb.personsがあると仮定します。 Mongoでは
db.persons.find({ }, {'personId' : 1})
で検索できます。VoyageMongoでは、JSONクエリに送信されるすべての辞書エントリが$とクエリに照合されるようです。 MongoQueryにはInstVarとAccessor to fieldsがありますが、それらを設定する方法はわかりません。 VoyageMongoで返品フィールドを指定する方法はありますか?私が見つけた唯一のオプションは、クラス、VOMongoRepository、VOMongoRepositoryResolverとするMongoCollectionを拡張することであったために検索した後VoyageMongoで返されるフィールドを指定してください

よろしく

マックス

答えて

0

。 メッセージチェーンを追加しました Class>>selectMany: aBlock options: someOptions ^self voyageRepository selectMany: self where: aBlock options: someOptions VOMongoRepository>>selectMany: aClass where: aDictionary options: someOptions | selected | selected := resolver selectMany: aClass where: aDictionary options: someOptions. ^aClass = aClass persistentClass ifTrue: [ selected ] ifFalse: [ selected select: [ :each | each isKindOf: aClass ] ] VOMongoRepositoryResolver>>selectMany: aClass where: aDictionary options: someOptions self execute: [ ^self basicSelectMany: aClass where: aDictionary options: someOptions ] VOMongoRepositoryResolver>>basicSelectMany: aClass where: aDictionary options: someOptions "Selecting instances of aClass should be done in the mongo query, not here" self flag: #todo. ^((self basicRawSelectMany: aClass where: aDictionary options: someOptions) collect: [ :each | self retrieveObjectOf: aClass json: each ] as: repository collectionClass) select: [ :each | each isKindOf: aClass ] VOMongoRepositoryResolver>>basicRawSelectMany: aClass where: aDictionary options: someOptions ^self pool withDatabase: [ :db | (self collectionAt: aClass inDatabase: db) select: aDictionary options: someOptions ] MongoCollection>>select: aDictionary options: someOptions ^self query: [:query | query where: aDictionary; limit: (someOptions at: 'limit' ifAbsent: nil); offset: (someOptions at: 'offset' ifAbsent: nil); fields: (someOptions at: 'fields' ifAbsent: nil) ]

これで問題が解決しました。 メッセージは、そのように送信されます。

options := { 'fields' -> { 'personId' -> 1 } asDictionary } asDictionary. 
^ self selectMany: [ :each | 
    (each at: 'name') = 'Max' ] 
    options: options 

1つはまた制限を追加し、オプションのディレクトリにオフセットすることができます。 私は多くのフィールドを持つオブジェクトを持っているので、それらのうちのほんの一部をフェッチするときのパフォーマンスが48000 msから229 msに変更されました。
拡張子を含むパッケージを作成しました。

関連する問題