-
Notifications
You must be signed in to change notification settings - Fork 1.1k
@MongoId(targetType = STRING)
forces _id : {…}
query documents to String
#3783
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
Comments
Because of this problem I had to change $in operator to $or. |
Same result "is" operator when use with Match operator.
|
Thanks for the details. Spring Data MongoDB performs an implicit type conversion to @Document
static class Foo{
String id;
}
Query query = new Query();
query.addCriteria(Criteria.where("_id").in(Arrays.asList("5b8bedceb1e0bfc07b008828", "5b8bedceb1e0bfc07b008829", "5b8bedceb1e0bfc07b00882a"))); renders {"_id": {"$in": [ObjectId("5b8bedceb1e0bfc07b008828"), ObjectId("5b8bedceb1e0bfc07b008829"), ObjectId("5b8bedceb1e0bfc07b00882a")]}} you can hint Spring Data to use a specific Id field type with @Document
static class Foo{
@MongoId
String id;
}
Query query = new Query();
query.addCriteria(Criteria.where("_id").in(Arrays.asList("5b8bedceb1e0bfc07b008828", "5b8bedceb1e0bfc07b008829", "5b8bedceb1e0bfc07b00882a"))); renders {"_id": {"$in": ["5b8bedceb1e0bfc07b008828", "5b8bedceb1e0bfc07b008829", "5b8bedceb1e0bfc07b00882a"]}} Note that the Mongo query is rendered using Mongo shell settings. |
Thank you for your reply. Id description like here on my side:
|
And sometimes I use custom data object (DTO) to mapping. Its not a mongodb document object and it has id field. But on custom object as same problem. |
Thanks a lot. What happens is that the |
@MongoId(targetType = STRING)
forces _id : {…}
query documents to String
Spring data version: 3.3.0-M2
I use "_id" field as a string type and I want to use this field with $in operator like this.
But console output is like this:
find using query: { "_id" : "{\"$in\" : [\"5b8bedceb1e0bfc07b008828\", \"5b8bedceb1e0bfc07b008829\", \"5b8bedceb1e0bfc07b00882a\"]}"} fields: Document{{}} for class:
But $in operator running properly with other fields.
find using query: { "tenantId" : "5b8bedceb1e0bfc07b00882f", "roleId" : { "$in" : ["5b8bedceb1e0bfc07b008828", "5b8bedceb1e0bfc07b008829", "5b8bedceb1e0bfc07b00882a", "5b8bedceb1e0bfc07b00882e", "5c6f3b1f1c36570fc572765c", "5eb8b5f540e3006cfa56de26"]}, "deleted" : false} fields: Document{{}} for class
On execution time the criteria api adding backslash "\" to the query and don't return any data.
The text was updated successfully, but these errors were encountered: