-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add $unset and $geoNear stages #998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1be03da
Add $unset and $geoNear stages, use Java tests
katcharov b58e17c
Address PR comments
katcharov 7151961
Use geoNearOptions() pattern
katcharov 9a21953
Fix checkstyle, file over 2000 lines
katcharov 38e179a
Partial revert prior, suppress FileLength, add doc
katcharov a88dffe
Use ConstructibleBson for geoNear options
katcharov d3d8d4b
Change public to private
katcharov 665f8dc
Use BsonDocumentWriter
katcharov 01121ed
Minor fixes
katcharov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
82 changes: 82 additions & 0 deletions
82
driver-core/src/main/com/mongodb/client/model/GeoNearConstructibleBson.java
This file contains hidden or 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,82 @@ | ||
/* | ||
* Copyright 2008-present MongoDB, Inc. | ||
* | ||
* 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 com.mongodb.client.model; | ||
|
||
import com.mongodb.annotations.Immutable; | ||
import com.mongodb.internal.client.model.AbstractConstructibleBson; | ||
import org.bson.BsonDocument; | ||
import org.bson.Document; | ||
import org.bson.conversions.Bson; | ||
|
||
final class GeoNearConstructibleBson extends AbstractConstructibleBson<GeoNearConstructibleBson> implements GeoNearOptions { | ||
/** | ||
* An {@linkplain Immutable immutable} {@link BsonDocument#isEmpty() empty} instance. | ||
*/ | ||
static final GeoNearOptions EMPTY_IMMUTABLE = new GeoNearConstructibleBson(AbstractConstructibleBson.EMPTY_IMMUTABLE); | ||
|
||
private GeoNearConstructibleBson(final Bson base) { | ||
super(base); | ||
} | ||
|
||
private GeoNearConstructibleBson(final Bson base, final Document appended) { | ||
super(base, appended); | ||
} | ||
|
||
private GeoNearOptions setOption(final String key, final Object value) { | ||
return newAppended(key, value); | ||
} | ||
|
||
@Override | ||
public GeoNearOptions distanceMultiplier(final Number distanceMultiplier) { | ||
return setOption("distanceMultiplier", distanceMultiplier); | ||
} | ||
|
||
@Override | ||
public GeoNearOptions includeLocs(final String includeLocs) { | ||
return setOption("includeLocs", includeLocs); | ||
} | ||
|
||
@Override | ||
public GeoNearOptions key(final String key) { | ||
return setOption("key", key); | ||
} | ||
|
||
@Override | ||
public GeoNearOptions minDistance(final Number minDistance) { | ||
return setOption("minDistance", minDistance); | ||
} | ||
|
||
@Override | ||
public GeoNearOptions maxDistance(final Number maxDistance) { | ||
return setOption("maxDistance", maxDistance); | ||
} | ||
|
||
@Override | ||
public GeoNearOptions query(final Document query) { | ||
return setOption("query", query); | ||
} | ||
|
||
@Override | ||
public GeoNearOptions spherical() { | ||
return setOption("spherical", true); | ||
} | ||
|
||
@Override | ||
protected GeoNearConstructibleBson newSelf(final Bson base, final Document appended) { | ||
return new GeoNearConstructibleBson(base, appended); | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
driver-core/src/main/com/mongodb/client/model/GeoNearOptions.java
This file contains hidden or 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,106 @@ | ||
/* | ||
* Copyright 2008-present MongoDB, Inc. | ||
* | ||
* 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 com.mongodb.client.model; | ||
|
||
import org.bson.Document; | ||
import org.bson.conversions.Bson; | ||
|
||
/** | ||
* The options for a {@link Aggregates#geoNear} pipeline stage. | ||
* | ||
* @mongodb.driver.manual reference/operator/aggregation/unwind/ $geoNear | ||
* @since 4.8 | ||
*/ | ||
public interface GeoNearOptions extends Bson { | ||
/** | ||
* Returns {@link GeoNearOptions} that represents server defaults. | ||
* | ||
* @return {@link GeoNearOptions} that represents server defaults. | ||
*/ | ||
static GeoNearOptions geoNearOptions() { | ||
return GeoNearConstructibleBson.EMPTY_IMMUTABLE; | ||
} | ||
|
||
/** | ||
* @param distanceMultiplier The factor to multiply all distances returned by the query. | ||
* @return a new {@link GeoNearOptions} with the provided option set | ||
* @since 4.8 | ||
*/ | ||
GeoNearOptions distanceMultiplier(Number distanceMultiplier); | ||
|
||
/** | ||
* This specifies the output field that identifies the location used to calculate the distance. | ||
* This option is useful when a location field contains multiple locations. | ||
* To specify a field within an embedded document, use dot notation. | ||
* | ||
* @param includeLocs the output field | ||
* @return a new {@link GeoNearOptions} with the provided option set | ||
* @since 4.8 | ||
*/ | ||
GeoNearOptions includeLocs(String includeLocs); | ||
|
||
/** | ||
* Specify the geospatial indexed field to use when calculating the distance. | ||
* | ||
* @param key the geospatial indexed field. | ||
* @return a new {@link GeoNearOptions} with the provided option set | ||
* @since 4.8 | ||
*/ | ||
GeoNearOptions key(String key); | ||
|
||
/** | ||
* The minimum distance from the center point that the documents can be. | ||
* MongoDB limits the results to those documents that fall outside the specified distance from the center point. | ||
* | ||
* @param minDistance the distance in meters for GeoJSON data. | ||
* @return a new {@link GeoNearOptions} with the provided option set | ||
* @since 4.8 | ||
*/ | ||
GeoNearOptions minDistance(Number minDistance); | ||
|
||
/** | ||
* The maximum distance from the center point that the documents can be. | ||
* MongoDB limits the results to those documents that fall within the specified distance from the center point. | ||
* | ||
* @param maxDistance the distance in meters for GeoJSON data. | ||
* @return a new {@link GeoNearOptions} with the provided option set | ||
* @since 4.8 | ||
*/ | ||
GeoNearOptions maxDistance(Number maxDistance); | ||
|
||
/** | ||
* Limits the results to the documents that match the query. | ||
* The query syntax is the usual MongoDB read operation query syntax. | ||
* | ||
* @param query the query | ||
* @return a new {@link GeoNearOptions} with the provided option set | ||
* @since 4.8 | ||
*/ | ||
GeoNearOptions query(Document query); | ||
|
||
/** | ||
* Determines how MongoDB calculates the distance between two points. | ||
* By default, when this option is not provided, MongoDB uses $near semantics: | ||
* spherical geometry for 2dsphere indexes and planar geometry for 2d indexes. | ||
* When provided, MongoDB uses $nearSphere semantics and calculates distances | ||
* using spherical geometry. | ||
* | ||
* @return a new {@link GeoNearOptions} with the provided option set | ||
* @since 4.8 | ||
*/ | ||
GeoNearOptions spherical(); | ||
} |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a
public static Bson unset(final List<String> fields)
version as well - this keeps it inline with other helpers.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated