Day upper Bound and Lower Bound for MongoDB Spring

Avi Patel :

I have a Database and i am saving logs as well for the each update performed by users on Database. I want to check if user is updating Data within 24 hours then update the Log, else if it's more than a day since data is updated then instead of updating the log for the day insert new log. for that i need to set upper bound and lower bound for the time on which data is inserted.

I have write down a function that will check if data is updated since 24 hours or not, but i dont know what to put as upper bound and lower bound for a day.

// returns 24 hours records, by Id and Crop...
    private FarmerCropDataLog findLogByIdAndCrop(Farmer farmer, Crop cropData) {

        String farmerId = farmer.getId();

        // TODO Auto-generated method stub
        Query query = new Query();
        query.addCriteria(Criteria.where(FarmerCropDataLog.Constants.FARMER_ID).is(farmerId));
        query.addCriteria(Criteria.where(FarmerCropDataLog.Constants.CROP).is(Crop.valueOf(Crop.class, cropData.name())));
        query.addCriteria(Criteria.where(FarmerCropDataLog.Constants.CREATION_TIME).lt(UPPER_BOUND));
        query.addCriteria(Criteria.where(FarmerCropDataLog.Constants.CREATION_TIME).gte(LOWERBOUND));
        List<FarmerCropDataLog> logData = farmerCropDataLogDao.runQuery(query, FarmerCropDataLog.class);
        if (logData != null) {
            return logData.get(0);
        } else {
            return null;
        }
    }

Edit ->

Upper Bound should be 24*60*60*1000 and lowerBound should be 0?

Pietro Martinelli :

Based on the info in the comments, I think you can valorize bounds values as follows:

long millisPerDay = 24 * 60 * 60 * 1000;
long upperBound = System.currentTimeMillis();
long lowerBound = upperBound - millisPerDay;

CAUTION: you should check whether you timestamp field uses Unix Timestamps (in seconds) or millis since 01/01/1970: in the first scenario, your values should be divided by 1000.

I hope this can help you tu setup your query properly...

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Generics - lower/ upper bound wild card behaviour?

Is it possible to specify both upper and lower bound constraints on type parameters in Java?

Lower and Upper Bound for Java Wildcard Type

rationale for std::lower_bound and std::upper_bound?

Difference between basic binary search for upper bound and lower bound?

upper_bound and lower_bound inconsistent value requirements

Difference between upper_bound and lower_bound in stl

How to interpret the upper/lower bound of a datapoint with confidence intervals?

Scala upper and lower type bound

using lower_bound/upper_bound with 2 different types

Multiple filters by lower and upper bound in R Shiny

Specify a range (upper and lower bound) for a variable in Python

Find an upper and lower bound of following code

How to find a upper and lower bound of code?

Questions about std::lower_bound and std::upper_bound

Parameter for upper and lower bound in linear programming solvers

lower_bound and upper_bound in Map of Pairs

how to update a node's lower and upper bound

Proving an upper and lower bound for an algorithm

Upper and Lower bound on scala type

How to get radius of lower and upper bound of circle?

Clarification on sorting-networks-size upper and lower bound

Determine upper and lower bound of list of values

Drawing line chart without lower and upper bound in c#

Having trouble understanding the upper bound and lower bound in the following R code

how to find lower bound and upper bound in pandas dataframe?

Naming of lower_bound, upper_bound c++

Binary search: Not getting upper & lower bound for very large values

Comparator function for upper_bound or lower_bound for vector of vector