How to get today's inserted documents in Couchbase? - couchbase

I want to get all the documents which were inserted today in couchbase. My document doesn't has any createdAt timestamp. Can someone please guide on how this can be achieved without adding any timestamp to document?

There are several N1QL date functions you can use to insert the current timestamp in a range of formats. You can find out more here:
https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/datefun.html#fn-date-clock-local

Related

Uploaded CSV file shows Date column as strings, how to convert to Dates for AutoAI use?

I was trying out the AutoAI feature on the IBM cloud with a CSV that only has two columns: a date column and a change column (1 or 0). When I upload it, as a data asset, it sees the Date column as a string. Even after going through data refinery and converting it to a date, when AutoAI reads the file, it still sees it as a column of strings.
How do I make AutoAI recognize the date column as a column?
Blockquote
Unfortunately , date recognition doesn't work on AutoAI at this moment. However, next year there is going to be an update of the autoai service where you will be able to have that feature. If you want to test it, there is a demo version of that: https://autoai.mybluemix.net/home
Blockquote
Just to add a comment to Aleksandar's comment regarding the AutoAI Demo: it is a research demo thus it is not exposed to the general public. It needs further authorization (either an IBM w3id or a special login/pwd through an IBM sales representative).
And to answer the question, we are fully aware the user needs for the TS dataset and the Date/Time detection function, and it will be out very soon.
Unfortunately , date recognition doesn't work on AutoAI at this moment. However, next year there is going to be an update of the autoai service where you will be able to have that feature. If you want to test it, there is a demo version of that: https://autoai.mybluemix.net/home
The time series support is not in place yet. There is on-going effort to have first version available this year.
There is workaround option but not perfect (AutoAI will NOT treat data as timeseries):
do the preprocessing / features creation on your own (create features like year, month, day, week etc.)
pass such preprocessed data to AutoAI
Drawbacks: it will not be treated as ts data. Model validation (cross-validation), folds building will not take into account time order what may lead to unreliable metrics values.

A field that stores the time the row was inserted and doesn't change it on update

According to what I've read in some posts such as the answer for this question
passing null value in a timestamp field will store the date when the row was created, but will update it when row is edited.
I want to do the same thing but without changing the date, and having that time stored as UTC, how can I do that?
The best approach is to create a trigger to apply the change, or do it in your application code.
As a note, TIMESTAMP fields are really awful and shouldn't be used as they are subject to the 2038 overflow issue while DATETIME is not. A DATETIME can go thousands of years into the past and into the future, which is hopefully enough.

SQL Date format in schema definition

For "date1" attribute of my table I am trying to insert date of the format
YEAR-MONTH-DAY HOUR:MIN:SEC
Do I have ot define this format in the schema?
All I have done is
date1 DATE NULL
I know I can use DATE_FORMAT(), but I think only for retrieving/querying purposes.
What about recording data in the table?
if you are trying to insert a date with the time you need to instantiate it with datetime
date1 DATETIME NULL
SEE DOCS
alternatively you can store it as a TIMESTAMP. both store in that format
Your schema is fine (though you'll need DATETIME if wanting to preserve the time component), there aren't formatting options for how a DATETIME type is stored.
As long as the data you're inserting has a valid datetime format (the one you posted is fine) then you don't need to do anything else. Some non-standard formats will require a fix prior to insert.
The DATE_FORMAT() function is for displaying a DATE/DATETIME in a chosen format, but how the data is stored is defined solely by the data type.

How to get only year from facet.fields contains full date field in Solr JSON?

How to get only year from facet.fields date field in Solr JSON ? Help me if you have solution.
As far as I know you will have to loop through the results and extract the year.
If extracting year from date is regular query to solr then it is preferable to index
year separately.
Hope this helps. In case you find a better solution do let me know.

Storing Calendar Data in MySQL

Just a quick architecture question really on storing calendar data.
Basically, I have a database of services for rental. On the front end, there is a calendar to show either "Available" or "Unavailable" for every future date. In the back-end the user can set any date/date range to available or unavailable (1 or 0) on a jQuery calendar.
The question I have is how would you go about storing this data in mysql and retrieving it on the front end?
Possible have all dates available and store the unavailable dates? Then if they are set to available again, remove the record for that date?
Cheers,
RJ
Possible have all dates available and store the unavailable dates? Then if they are set to available again, remove the record for that date?
Yes, I'd go with that, except I would not remove the record when renting expires - you'll easily know a renting expired because it's in the past, so you automatically keep the history of renting as well.
After all, there is infinite number of available dates1, so you'd have to artificially limit the supported range of dates if you went the other way around (and stored free dates).
1 In the future. And, in some sense, in the past as well.
Also, I'm guessing you want some additional information in case a service is rented (e.g. name of the renter) and there would be nowhere to store that if renting were represented by a non-existent row!
Since the granularity of renting is a whole day, I think you are looking at a database structure similar to this:
Note how RENTING_DAY PK naturally prevents overlaps.
Alternatively, you might ditch the RENTING_DAY and have START_DATE and END_DATE directly in RENTING, but this would require explicit range overlap checks, which may not scale ideally.
Decide whether the default is Available or Unavailable.
Possible have all dates available and store the unavailable dates?
So default is Available?
Then you can put unavailable_start and unavailable_end - store it as a date field. For single days, unavailable_start = _end. Then it's easy to query for a month or any date range and return the unavailability periods in that range. Then have jQuery parse it to display the calendar details for those dates.