-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolves #353: Add support for $arrayElemAt, $ifNull, $dateToString a…
…nd typesafe $lookup shortcut
- Loading branch information
Showing
7 changed files
with
178 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
kmongo-core/src/main/kotlin/org/litote/kmongo/SyncProperties.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (C) 2016/2022 Litote | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.litote.kmongo | ||
|
||
import com.mongodb.client.MongoCollection | ||
import kotlin.reflect.KProperty1 | ||
|
||
/** | ||
* Creates a $lookup pipeline stage for the specified filter (Typesafe version) | ||
* | ||
* @param from the collection in the same database to perform the join with. | ||
* @param localField specifies the field from the local collection to match values against. | ||
* @param foreignField specifies the field in the from collection to match values against. | ||
* @param newAs the name of the new array field to add to the input documents. | ||
* @return the $lookup pipeline stage | ||
* @mongodb.driver.manual reference/operator/aggregation/lookup/ $lookup | ||
*/ | ||
fun <FROM : Any> lookup( | ||
from: MongoCollection<FROM>, | ||
localField: KProperty1<out Any, Any?>, | ||
foreignField: KProperty1<FROM, Any?>, | ||
newAs: KProperty1<out Any, Any?> | ||
) = | ||
lookup(from.namespace.collectionName, localField.path(), foreignField.path(), newAs.path()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
kmongo-property/src/test/kotlin/org/litote/kmongo/ProjectionTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (C) 2016/2022 Litote | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.litote.kmongo | ||
|
||
import org.junit.Test | ||
import kotlin.test.assertEquals | ||
|
||
/** | ||
* | ||
*/ | ||
class ProjectionTest { | ||
|
||
class ProjectionData(val s: String) | ||
|
||
@Test | ||
fun testProjectionWith() { | ||
assertEquals("\$s.a", ProjectionData::s.projectionWith("a")) | ||
} | ||
} |