NVL / COALESCE equivalent in MongoDB - mongodb

I'm new to MongoDB. I'm using SpringBoot JPA with MongoDB
I want to convert below MySql query to MongoDB
select * from table_name where FIELD1=COALESCE( '0?', FIELD1) and FIELD2=COALESCE( '1?', FIELD2) and FIELD3=COALESCE( '2?', FIELD3)
I need to write it in #Query("some Mongo query")

Related

Orientdb - query in multiple databases

I need create a query using multiples Orientdb Databases.
Ex:
I tried something like that in database1.
select from vertex1 where field1 in ( select field2 from database2:vertex2)
Is It possibly create a SQL query in OrientdbDB using multiples database?

Finding a user-defined column from collection without grouping

How do I find a user-defined column from a collection without putting it in a group in mongodb query?
I would like to convert the following SQL query to mongo:
SELECT
brand_name,
count(`qty/inventory`) AS totalstock,
count(if(`qty/inventory`=0, `qty/inventory`, NULL)) as outofstock,
count(if(`qty/inventory`!=0, `qty/inventory`, NULL)) as availablestock,
DATE_ADD(stock_updated_at, INTERVAL 318 minute) as stock_updated_at
FROM tbl_kunuzdatafeed_master
GROUP BY brand_name
ORDER BY stock_updated_at desc;
Can anyone help with converting this to mongo query?

Spring Data JPA subquery in from

Spring DATA JPA support subquery in from ?
like
select * from (
select unique_id
from table_a
) as from_a
inner join table_b
on from_a.unique_id = table_b.unique_id
querydsl JPASubquery or Spring DATA criteria impossible?
I think it is noe possible.
in other way. you use JPAExpressions. it will be serching for subquery in query dsl.
But i aleardy user that subQuery that are result only one table.

Equivalent Postgres query for an Oracle query

Which Postgres query is equivalent to the following Oracle query?
select CID,
max(cus.customer_id) keep (dense_rank first order by decode(acct.CUS_Type,'X',4,'M',5,'F',6,'G',7,'I',5,6), start_date) best_CUS
from cusomer cus
group by CID ;

QueryDSL - add subquery into FROM statement

I need to implement sql query like:
SELECT * FROM (SELECT a FROM b WHERE a.z = 1) WHERE rownum <=1;
How can I write such statement with QueryDSL (I am not using JPA and JDO - only clean sql)?
Querydsl SQL emulates paging of all the supports databases, so you can write directly
query.from(a)
.where(a.z.eq(1))
.limit(1)
.list(a);
If you need to write this via a subquery then like this
query.from(
new SQLSubQuery().from(a).where(a.z.eq(1)).list(a).as(a))
.where(rownum.loe(1))
.list(a);