Comments (5)
You can not do that, you need to create an class for a result, please take a look here: https://youngmonkeys.org/ezydata/guides/ezymongo-custom-query-result
from ezydata.
I mean i do all required:
Do i need this file if i use a StringValueResult?
StringValue:
@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class StringValue {
@EzyId
Long id;
String email;
String username;
String password;
}
Custom Query:
@EzyRepository("accountRepo")
public interface AccountRepo extends EzyMongoRepository<Long, Account>{
@EzyQuery("{$query: {?0:'?1'},{_id:0, ?2:1}")
StringValueResult getStringFieldByValue(String field, String value, String retValue);
}
StringValueResult:
@Data
@EzyQueryResult
@NoArgsConstructor
@AllArgsConstructor
public class StringValueResult {
String username;
}
Call:
StringValueResult value = accountService.getStringFieldByValue("email", request.getEmail(), "username");
logger.info(value.getUsername());
Same Error as i descriped before:
readStartArray can only be called when CurrentBSONType is ARRAY, not when CurrentBSONType is DOCUMENT.
is my Custom query right or allowed or what ive done wrong?
@EzyQuery("{$query: {?0:'?1'},{_id:1, ?2:1}")
And i ask before i want to create a universal function that i use in different ways and i dont want create for each single value create a own custom query, result class to get one time the username next time the emailaddress and so on. Now it the field is a username is der some solution if you take a look on the call:
StringValueResult value = accountService.getStringFieldByValue("email", request.getEmail(), "username");
StringValueResult value = accountService.getStringFieldByValue("someotherfield", someothervalue, "someotherfield");
from ezydata.
ah, now I understand you mean, so you can do like this:
- Create
findStringFieldByValue
in your repo
@EzyQuery("{$query: {?0:?1}, $fields: [?2], $orderBy: {_id:1, ?2:1}}")
Account findStringFieldByValue(String field, String value, String retValue);
- Get the the field you want
Because this query will use projection so you don't need to worry about performance, you can check logs to see, example:
09:11:53.736 [main] DEBUG com.tvd12.ezydata.mongodb.testing.bean.PersonRepo$EzyDatabaseRepository$EzyAutoImpl$6 - find one with query: {$query: {'personName':'dzung'}, $fields: ['personName'], $orderBy: {_id:1, 'personName':1}}
09:11:53.737 [main] DEBUG org.mongodb.driver.protocol.command - Sending command '{"find": "test_mongo_bean_person", "filter": {"personName": "dzung"}, "projection": {"personName": 1}, "limit": 1, "singleBatch": true, "$db": "test", "lsid": {"id": {"$binary": {"base64": "jjD1P/zhR+KgCDkmXbdsjg==", "subType": "04"}}}}' with request id 12 to database test
from ezydata.
Thank you, it works but not realy happy with this behaviour. But if you say there is no performance issue i can live with that. I tested it all and other fields are empty only the id and the requested field has values;
Maybe it is only in my head but it would be nice or some feature request vor a new standard query i mean there are lot of usecases for it to get simple values (int or string) by given field and value pair:
@EzyQuery("{$query: {?0:'?1'},{_id:0, ?2:1}")
getFieldValueByFieldAndValue(String field, String value, String fieldValue);
and to get the datas out with:
var value = accountService.getFieldValueByFieldAndValue("email", '[email protected]', username);
logger.info(value.getMyRequestedField());
Thanks a lot again to giving me your time.
from ezydata.
Actually, mongodb always return BsonObject (Document or Array) so return only single value is hard, but let me think, thank you.
from ezydata.
Related Issues (3)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ezydata.