I have a collection with all document ids as epochtime(1613728796). Each of these documents contains up to 50 fields in it. I wanted to query set of documents between specific timing. How I can query based on document's uid?
Query query = db.collection("my-collection").whereGreaterThan("uid", "1613728796")
Try this:
Query query = db.collection("my-collection").whereGreaterThan("__name__", "1613728796").whereLessThan("__name__", "1613728796")
Replace the above epoch times with the correct ones.
If that doesn't work, try replacing "__name" with FieldPath.documentId() or FieldPath.documentId
Related
I'm looking to perform a query on my Couchbase database using the Java client SDK, which will return a list of results that include the document id for each result. Currently I'm using:
Statement stat = select("*").from(i("myBucket"))
.where(x(fieldIwantToGet).eq(s(valueIwantToGet)));
N1qlQueryResult result = bucket.query(stat);
However, N1qlQueryResult seems to only return a list of JsonObjects without any of the associated meta data. Looking at the documentation it seems like I want a method that returns a list of Document objects, but I can't see any bucket methods that I call that do the job.
Anyone know a way of doing this?
You need to use the below query to get Document Id:
Statement stat = select("meta(myBucket).id").from(i("myBucket"))
.where(x(fieldIwantToGet).eq(s(valueIwantToGet)));
The above would return you an array of Document Id.
I have have a mongo collection that keeps state records for devices. Thus, there could be multiple records per device. What I would like to do is create a query through the mongoTemplate that gets the latest record for each device.
Here's the constraints:
Pass in a Set<'String'> name_ids, regular field within mongo collection not the _id or found within the _id
get only the latest record for each device with matching name_id
return List<'DeviceStateData'> (No duplicates should be found with the same name_id)
example of collection object:
{
_id: "241324123412",
name_id: "flyingMan",
powerState:"ON",
timeStamp: ISODate('')
}
Thanks
You should look on Distinct function.
Here you can find details with Spring.
I have many documents on my elasticsearch. I am using elasticsearchTemplate.queryForList(SearchQuery, class) to get the documents depending on my query. This query always return 10 documents. Does elasticsearch provide any api where all the documents that match the query will be returned?
You need to add Page Request in your searchQuery.
NativeSearchQueryBuilder builder = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withPageable(new PageRequest(0, repository.count() as int))
SearchQuery query = builder.build()
Repository.count() will give the count of documents in your index.
Hope this helps.
A criteria is used to retrieve data from database. It generates SQL Query perfectly, which is tested on mySql separately and the records are loaded correctly;However, when using Criterial.list() it gives me an empty list.
I have checked my DB connections, and they are all correct. What would have caused this problem?
UPDATED
Here is my code:
accCr = DetachedCriteria.forClass(TSESpotInvestorAccount.class, "acc");
accCr.setResultTransformer(DetachedCriteria.DISTINCT_ROOT_ENTITY);
accCr.add(Restrictions.eq("exchangeDepositNo", filter.getBc()));
accCr.setProjection(Projections.id());
List accIds = getHibernateTemplate().findByCriteria(accCr);
Your code doesn't make much sense:
accCr.setResultTransformer(DetachedCriteria.DISTINCT_ROOT_ENTITY);
The above line says that the query is supposed to return entities (with, potentially, joined entities), and that Hibernate should return only distinct entities
accCr.setProjection(Projections.id());
The above line says that the query must only return one scalar column: the ID of the root entity.
If what you want is a list of IDs, then don't set the distinct root entity result transformer.
I want to process the count column in my action how to do with help of hiberante.in my application every class is mapped to every table here I'm using billing table. In billing table details and other columns are there.
If i pass the query into execute sql query method it getting all the details, but it returns the count column as that corresponding dao class. How to process that column. Here is my query.
select u,b,b,count(b.details) from com.cod.model.Billing b,com.cod.model.User u where b.accountId=u.id and b.details not like '%Monthly Package With Usage Value Rs:0.0%' and b.details not like '%A/C Opened:%' and b.details not like '%Voucher Recharged%' and b.details not like '%default0%' group by u.username,b.details
Here it's getting user and billing table values but count column also comes as billing table object.
Don't make the results list type safe or hibernate will grab everything he can and push it in an instance of that object. When you make your results list not type safe hibernate will just return an List over which you can iterate and retrieve the fields you need.
List.get(0)[3] should result in you having your count.
String hql = "...";
Query query = session.createQuery(hql);
//List< com.cod.model.Billing> results = query.list();
List results = query.list();