In my mongorepository I have a function called:
findByParticipantIdsContaining(String participantId);
What is the mongo operation used for Containing? I thought it'd be something like:
Criteria containsParticipantId = where(participantId).in("participantIds");
but it's not...
EDIT
I think it may be:
Criteria containsParticipantId = where("participantIds").is(participantId);
I'll give it a test.
The Spring containing operation looks like a LIKE operation in MySQL. In mongo, LIKE operator doesn't exist but instead you can use is operator as you suggested but with a regex as value
Related
Say that I have use case for finding method annotated via say #Scheduled(cron = "${variable}"), and I'd like to know the value of "cron" parameter. If I check via reflection, no surprise, I will find there value "${variable}".
Can someone share link/snipet how to evaluate variables/spel expression present in annotation? I found some answers, but neither of them worked.
Just to extend #crizzis answer, maybe filling the missing part.
Fist you need to inject/autowire ConfigurableBeanFactory beanFactory;. Looking at implementation of ExpressionValueMethodArgumentResolver and it's parent AbstractNamedValueMethodArgumentResolver it seems to me, that full code which does variable substitution and spell needs one more line:
BeanExpressionResolver beanExpressionResolver = beanFactory.getBeanExpressionResolver();
String expressionWithSubstitutedVariables = beanFactory.resolveEmbeddedValue(expression);
Object resultWithResolvedSPEL = beanExpressionResolver.evaluate(expressionWithSubstitutedVariables, new BeanExpressionContext(beanFactory, null));
then string like #{!${some-boolean-variable} ? 'a' : 'b'} was correctly evaluated for me. Not sure if this is the way-to-go as I don't know spring well, but this worked for me.
I'm sure there are a couple of ways, but the easiest is probably:
beanFactory.getBeanExpressionResolver().evaluate(
"${variable}",
new BeanExpressionContext(beanFactory, null))
I'm currently building a FHIR (R4) Server, and i try to implement the following request:
[base]/PractitionerRole?practitioner.active:not=true
I know that active is a Token Param, and thanks to HAPI, i can use the following command :
TokenParam tokenSubject = referenceParam.toTokenParam(myContext);
But sadly, all the modifier part is lost : in my referenceParam, i only have a chain part (active:not), and a value part (true), so i don't have any modifiers, missing, etc..
So when i convert it to a TokenParam, i don't have neither the modifiers, missing, etc ...
So here is my question : Is there a way to have a ReferenceParam that has modifiers?
I would like to have a chain part (active), a modifier (not) and a value (true), as in a real TokenParam
Your syntax looks correct. My best guess is you're using token search directly, instead of as part of a chain.
Token/Identifier alone would be appropriate if you were searching for active directly on PractionerRole.
For example: http://hapi.fhir.org/baseR4/PractitionerRole?active:not=true
However, you're doing a nested search with ?practitioner.active:not=true
Try Search Parameters > 4.5.9 Chained Resource References > Dynamic Chains
For example: http://hapi.fhir.org/baseR4/PractitionerRole?practitioner.active:not=true
NB: active:not=true will return both active:missing and active=false
I'm currently writing an aggregation query for MongoDB in my Spring project in which I'm using $project operator. Within this operator I would like to compare two fields in order to return the result as projected "matches" key value. Here's the mongoDB shell equivalent (which works):
{$project:
{matches:
{$eq: ["$lastDate", "$meta.date"]}
}
}
I've read Spring Data MongoDB documentation and found some useful info about ProjectionOperator's 'andExpression' method which uses SpEL. The result Java code of my investigation was:
new ProjectionOperation().andExpression("lastDate == meta.date").as("matches")
Unfortunately I'm receiving exception:
java.lang.IllegalArgumentException: Unsupported Element:
org.springframework.data.mongodb.core.spel.OperatorNode#70c1152a Type: class org.springframework.data.mongodb.core.spel.OperatorNode You probably have a syntax error in your SpEL expression!
As far as I've checked, Spring Data MongoDB handles all Arithmetic operators correctly but cannot handle the comparison ones. Therefore I want to ask is there any other way to create such query with Spring Data MongoDB? Or maybe I don't know something crucial about SpEL?
I resolved this issue by passing JSON aggregate command (created with DBObjects in order to preserve flexibility of the query) to MongoDB, i.e.:
MongoOperations#executeCommand(DBObject command)
I'm trying to use CallableStatements to get the value of IDENTITY() in HSQLDB from Java JDBC.
I can prepareCall fine. The issue is with registerOutputParameter. I get "parameter index out of range" no matter what index I pass in.
I've tried SQL snippets like "{? = CALL IDENTITY()}" with no luck.
Any clues? Am I completely off track in how to invoke HSQLDB function routines from JDBC?
Instead of using IDENTITY(), use getGeneratedKeys() to retrieve any keys generated by the (insert) statement.
Note that you do need to use one of the Statement.execute... or Connection.prepare... methods that will enable this feature.
Gah.
http://sourceforge.net/tracker/index.php?func=detail&aid=3530755&group_id=23316&atid=378134
Output parameters for function invocation is not supported. Use executeQuery and grab the ResultSet.
I'm using Mongoid (v3) to access MongoDB, and want to perform this action:
db.sessionlogs.update(
{sessionid: '12345'}, /* selection criteria */
{'$push':{rows: "new set of data"}}, /* modification */
true /* upsert */
);
This works fine in the mongo shell. It's also exactly what I want since it's a single atomic operation which is important to me as I'm going to be calling it a lot. I don't want to have to do two operations -- a fetch and then an update. I've tried a bunch of things through mongoid, but can't get it to work.
How can I get MongoID out of the way and just send this command to MongoDB? I'm guessing there's some way to do this at the Moped level, but the documentation of that library is basically non-existent.
[Answer found while writing the question...]
criteria = Sessionlogs.collection.find(:sessionid => sessionid)
criteria.upsert("$push" => {"rows" => datarow})
Here is one way to do it:
session_log = SessionLog.new(session_id: '12345')
session_log.upsert
session_log.push(:rows, "new set of data")
Or another:
SessionLog.find_or_create_by(session_id: '12345').
push(:rows, "new set of data")
#push performs an atomic $push on the field. It is explained on the
Atomic Persistence page.
(Note: the examples use UpperCamelCase and snake_case as is Ruby convention.)
Don't go down to moped just yet, you can use find and modify operation to achieve the same thing (with all the default scope and inheritance goodies)
Sample to save an edge in a graph if not existed
edge = {source_id: session[:user_id],dest_id:product._id, name: edge_name}
ProductEdge.where(edge).find_and_modify(ProductEdge.new(edge).as_document,{upsert:true})