How to fetch string in particular key in firebase - iphone

I have firebase data as below:
chats
|
|
+ - - -simplelogin48simplelogin50
|
|
|
+ - - simplelogin50simplelogin48
|
|
|
+ - - -simplelogin48simplelogin50
Now I want to fetch chat data which contains "simplelogin 48". Is it is possible?

No, Firebase does not support a contains operator in its queries. Firebase provides queryStartingAtValue and queryEndingAtValue operators for selecting a range of keys, but they are both based on the start of the key (or property value or priority if you've ordered on those). See this section of the Firebase iOS documentation that explains querying.
So by:
[[[[ref queryOrderedByKey] queryStartingAtValue:#"simplelogin48"] queryEndingAtValue:#"simplelogin48"]
You would get:
+ - - -simplelogin48simplelogin50
+ - - -simplelogin48simplelogin50
But not:
+ - - simplelogin50simplelogin48
The way to work around this is by creating a so-called index node, which in this case simply lists the chat ids for each user:
chats_by_user
|
+ - - simplelogin48
| |
| + - - simplelogin48simplelogin50
| |
| + - - simplelogin48simplelogin49
| |
| + - - simplelogin50simplelogin48
|
+ - - simplelogin49
| |
| + - - simplelogin48simplelogin49
|
+ - - simplelogin50
|
+ - - simplelogin50simplelogin48
|
+ - - simplelogin48simplelogin50
With this structure you can simply access chats_by_user/simplylogin48 to get all references to all chats for that user.

Related

time_bucket_gapfill (TimescaleDB) : how to shift or set the start of the gapfill periods?

(I am using PostgreSQL 11.7-2 and TimescaleDB 1.6.1 with Ubuntu Server 18.04.4)
I am aggregating data with gaps with the time_bucket_gapfill function but contrary to the time_bucket function I can't find a way to set an offset or origin to the time bucket intervals. Here's an example:
Let's say I have this table:
DROP TABLE IF EXISTS demo;
CREATE TABLE demo
(
t TIMESTAMP WITH TIME ZONE NOT NULL,
val REAL
);
SELECT create_hypertable('demo', 't');
INSERT INTO demo(t, val) VALUES
('2020-05-28T11:00:40', 1),
('2020-05-28T11:01:45', 5),
('2020-05-28T11:02:10', 15),
('2020-05-28T11:03:35', 30)
;
I would like to aggregate data every minute but starting from 11:00:30, so here there will be a gap between 2:30 and 3:30 which value will be interpolated from previous and next values like this:
0 -------------
30 - - - - - - - - - - <<<<<
1
1' ------------- average : 1
1'30 - - - - - - - - - -<<<<<
5
2'00 ----------- average : 10
15
2'30 - - - - - - - - - -<<<<<
3'00 ----------- average (interpolated) : 20
3'30 - - - - - - - - - -<<<<<
30
4'00 ----------- average : 30
4'30 - - - - - - - - - -<<<<<
But when I run the following commands, the aggregation starts from 0 seconds, not from 30 seconds, and they do not return the expected previous average values:
SELECT time_bucket_gapfill('1 minutes', t,
start=>'2020-05-28T11:00:30',finish=>'2020-05-28T11:04:00') AS dtime,
avg(val) AS valavg, interpolate(avg(val))
FROM demo
GROUP BY dtime
ORDER BY dtime ASC;
returns
dtime | valavg | interpolate
------------------------+--------+-------------
2020-05-28 11:00:00+02 | 1 | 1
2020-05-28 11:01:00+02 | 5 | 5
2020-05-28 11:02:00+02 | 15 | 15
2020-05-28 11:03:00+02 | 30 | 30
(4 rows)
and
SELECT time_bucket_gapfill('1 minutes', t) AS dtime,
avg(val) AS valavg, interpolate(avg(val))
FROM demo
WHERE t BETWEEN '2020-05-28T11:00:30' AND '2020-05-28T11:04:00'
GROUP BY dtime
ORDER BY dtime ASC;
returns
dtime | valavg | interpolate
------------------------+--------+-------------
2020-05-28 11:00:00+02 | 1 | 1
2020-05-28 11:01:00+02 | 5 | 5
2020-05-28 11:02:00+02 | 15 | 15
2020-05-28 11:03:00+02 | 30 | 30
2020-05-28 11:04:00+02 | |
(5 rows)
How can I shift the origin of the time bucket intervals with time_bucket_gapfill ?

PostgreSQL - Pull earliest timestamp per user

I have a table which records each time the user performs a certain behavior, with timestamps for each iteration. I need to pull one row from each user with the earliest timestamp as part of a nested query.
As an example, the table looks like this:
+ row | user_id | timestamp | description
+ 1 | 100 | 02-02-2010| android
+ 2 | 100 | 02-03-2010| ios
+ 3 | 100 | 02-05-2010| windows
+ 4 | 111 | 02-01-2010| ios
+ 5 | 112 | 02-03-2010| android
+ 6 | 112 | 02-04-2010| android
And my query should pull just rows 1, 4 and 5.
Thanks!
This should be help. Don't understand your nested query part.
SELECT user_id, MIN(timestamp) AS min_timestamp
FROM table1
GROUP BY user_id
ORDER BY user_id;

grails mongodb 3.0.2 plugin join queries on associations using createCriteria()

I am trying to search for users with particular role using createCriteria().I have three domain classes: User, Role and UserRole (they are from SpringSecurity).
class UserRole implements Serializable {
User user
Role role
static constraints = {
user nullbale: false
role nullable: false
}
static mapping = {
version: false
id composite: ['role', 'user']
}
}
I am searching on isActive, name or username fields on User Domain and authority field on Role Domain .
def c = UserRole.createCriteria()
def results = c {
user {
eq("isActive", true)
or {
ilike("name", "somename")
ilike("username", "someusername")
}
}
role {
eq("authority", "ROLE_USER")
}
}
On running this I get UnsupportedOperationException from mongo plugin. Here is stacktrace
ERROR errors.GrailsExceptionResolver - UnsupportedOperationException occurred when processing request: [GET] /users/search - parameters:
query:
Join queries are not supported by MongoDB. Stacktrace follows:
Message: Join queries are not supported by MongoDB
Line | Method
->> 162 | handle in org.grails.datastore.mapping.mongo.query.MongoQuery$2
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 142 | handle in ''
| 1091 | populateMongoQuery in org.grails.datastore.mapping.mongo.query.MongoQuery
| 993 | executeQuery in org.grails.datastore.mapping.mongo.query.MongoQuery$58
| 861 | doInDB . . . . . . in ''
| 833 | doInDB in ''
| 542 | list . . . . . . . in org.grails.datastore.mapping.query.Query
| 325 | invokeMethod in grails.gorm.CriteriaBuilder
| 17 | $tt__searchUsers . in com.themopi.apis.searchactivity.SearchService
| 29 | searchUser in com.themopi.apis.search.SearchController
| 198 | doFilter . . . . . in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 106 | processFilterChain in com.odobo.grails.plugin.springsecurity.rest.RestTokenValidationFilter
| 72 | doFilter in ''
| 53 | doFilter . . . . . in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
I found a Jira on this issue but it is unresolved.
Any work around for this till now as jira was created on 09/Mar/12 or I am missing something?
I will be using pagination and projections in this query?
Any help or guidance is highly appreciated.
Thanks in advance.
there's an excellent article from Burt on this topic.
One of the main parts of it is, that the security model should be implemented with embedded/sub-doc entities. Actually joins shouldn't be used with mongo at all, and if you need those, use a RDBMS or Graph DB.

Grails audit logging plugin for mongodb is not working

I am using grails 2.2.3 , mongodb 1.3.3 the curd operation is working fine.
I want to log my curd operation
so i use audit-logging plugin "audit-logging:1.0.0",it work fine with mysql-database but not with mongodb.It shows
Error 2014-05-05 15:45:04,117 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error initializing the application: Cannot get property 'datastores' on null object
Message: Cannot get property 'datastores' on null object
Line | Method
->> 90 | doCall in AuditLoggingGrailsPlugin$_closure1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 303 | innerRun in java.util.concurrent.FutureTask$Sync
| 138 | run . . in java.util.concurrent.FutureTask
| 886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
| 908 | run . . in ''
^ 662 | run in java.lang.Thread
Any one came across this issue.
help me to solve this.
Thanks in advance. cheers..
I suggest your report the issue http://jira.grails.org/browse/GPAUDITLOGGING

SHOW STATUS LIKE in Sphinx SE

After executing that query
select count(*) from tablename WHERE query=';';
that query will return count as 20.
But that table having totally 771498 records. while execute on SHOW STATUS LIKE 'sphinx_%';
it has return like this
+--------------------+--------+
| Variable_name | Value |
+--------------------+--------+
| sphinx_error | 5732 |
| sphinx_time | 837 |
| sphinx_total | 1000 |
| sphinx_total_found | 771498 |
| sphinx_word_count | 0 |
| sphinx_words | |
+--------------------+--------+
Here i have doubt .
what is sphinx_error?
what is sphinx_time?
what is sphinx_total?
what is sphinx_total_found?
what is sphinx_word_count?
what is sphinx_words?
It will be very helpful for me. Advance thanks
firstly sphinxse is not a real mysql table. Its a fake table. It accepts a query, then sphinxse forwards it to a running instance in the background, and returns the results to produce a 'table' to mysql.
So count(*) wont work. It simply runs the query and counts the rows. There are only 20 rows, unless you ask for more.
sphinx_error? - indicates an error - maybe SHOW WARNINGS would get the text.
sphinx_time? - how long in milisecons the query took
sphinx_total? - how many records you can actully retrieve (subject to max_matches)
sphinx_total_found? - how many records actully match
sphinx_word_count? - the number of words in your query
sphinx_words? - how many docs/hits match each of the words - because you have no query, its empty.