I'm trying to run a query on my firebase database in order to return only those results where timestamp = the date specified in the date picker (see picture of app) I want this query to run whenever I press the view records button
[![Firebase][3]][3]
I am able currently to print out all objects into the recycler view, however when attempting to run my query its not producing any results, no errors and no faults in debugging
If I need to provide anymore detail please let me know
[3]: https://i.stack.imgur.com/d2uu2.png
To solve this, please change the following line of code:
options = new FirebaseRecyclerOptions.Builder<Records>().setQuery(databaseReference, Records.class).build();
to
options = new FirebaseRecyclerOptions.Builder<Records>().setQuery(query, Records.class).build();
// ^ ^
You have to pass to the setQuery() method the query object and not the databaseReference object because the query object actually filters your data.
Edit:
According to your comment:
Yep its working when hardcoded, but it's not working when getting the text view to string
This means that passing the query object did the trick but the problem remains on how you convert the data to String. To sovle this, be sure that the String representation of the date is of type: 04-02-2017 and your problem will be solved.
Related
I'm developing an Android app and I need to make a complex query on my Firestore database and create a FirestoreRecyclerAdapter. To create the adpater I need a FirestoreRecyclerOptions object that take in input the whole query. Reading the documentation, I can't use in my query the methods whereGreaterThan, whereLessThan, oderBy, etc, on different parameters. For example, how can I get users from db who have age greater than/less than AND who have weight greater than/less than?
For example the document's structure in my firestore database is:
Users --->UserID--->userName(String)
--->userAge(number)
--->userHeight(number)
--->userWeight(number)
FirebaseFirestore db;
db = FirebaseFirestore.getInstance();
RecyclerView recyclerView;
recyclerView = (RecyclerView)findViewById(R.id.recyclerViewID);
.
.
.
Query query = db.collection("Users").//the complex query that i need
FirestoreRecyclerOptions<User> options = new FirestoreRecyclerOptions.Builder<User>()
.setQuery(query, User.class)
.build();
adapter = new UsersAdapter(options, this);//get in input options and the context
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(adapter);
Edit: A possible solution in my last comment to answer 1
There are some query limitations when it comes to Firestore:
Query limitations
Cloud Firestore does not support the following types of queries:
Queries with range filters on different fields, as described in the previous section.
So you cannot query your database on range filters using whereGreaterThan() and whereLessThan() methods on different properties and pass it to an adapter.
Edit:
A possible solution for this issue would be to filter your records client side twice. First query the database using the first property and second using the second property. Unfortunately you cannot achieve this in a single go.
Edit2:
The solution would be to query the database using the first query, get the corresponding elements, query the database again using the second query and get the corresponding elements and then merge the results client side. Now the elements from the database were filtered twice. Pass a list of that elements to an adapter and that's it. Note, when using this solution you cannot use the Firebase-UI library anymore but this how you can get your items filtered twice.
I want to query my Workout Collection for the latest workout from a routine. Meaning I query with whereEqualTo my routineKey, order it by the Started TimeStamp in descending order and then limit to 1 and then take the this 1st Key/Id of the Workout.
However this does not work. whereEqualTo and orderBy work separately but not combined. What am I doing wrong?
fm.getColRefWorkout().whereEqualTo("routineKey", routineKey).orderBy("startTimeStamp", Query.Direction.DESCENDING).limit(1).get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
#Override
public void onSuccess(QuerySnapshot documentSnapshots) {
workoutKey = documentSnapshots.getDocuments().get(0).getId();
//To stuff with this workoutKey
}
});
This query will not work unless you create an index for it. This can be done, by creating it manually in your Firebase Console or if you are using Android Studio, you'll find in your logcat a message that sounds like this:
FAILED_PRECONDITION: The query requires an index. You can create it here: ...
You can simply click on that link or copy and paste the URL into a web browser and your index will be created automatically.
I am trying to print all users I have saved on Parse database on my screen. But somehow it doesn't work, I can print the data from all other tables expect the users...
I think the problem is somewhere here, because when I change the "Todo" to User table it doesn't work anymore...
mainAdapter = new ParseQueryAdapter<ParseObject>(this, "Todo");
mainAdapter.setTextKey("title");
any suggestions? Thanks!
The user class is special (so are a couple of others) because it's built into the platform. The name doesn't work because the name is private. As you can see _Users is the private name, but you shouldn't use it - you can't guarantee it won't change. The correct way to query is:
ParseQuery<ParseUser> query = ParseUser.getQuery();
I have been trying to retrieve information from querying a specific Asset(Story/Defect) on V1 using the VersionOne.SDK.Java.APIClient. I have been able to retrieve information like ID.Number, Status.Name but not Requests.Custom_SFDCChangeReqID2 under a Story or a Defect.
I check the metadata for:
https://.../Story?xsl=api.xsl
https://.../meta.V1/Defect?xsl=api.xsl
https://.../meta.V1/Request?xsl=api.xsl
And the naming and information looks right.
Here is my code:
IAssetType type = metaModel.getAssetType("Story");
IAttributeDefinition requestCRIDAttribute = type.getAttributeDefinition("Requests.Custom_SFDCChangeReqID2");
IAttributeDefinition idNumberAttribute = type.getAttributeDefinition("ID.Number")
Query query = new Query(type);
query.getSelection().add(requestCRIDAttribute);
query.getSelection().add(idNumberAttribute);
Asset[] results = v1Api.retrieve(query).getAssets();
String RequestCRID= result.getAttribute(requestCRIDAttribute).getValue().toString();
String IdNumber= result.getAttribute(idNumberAttribute).getValue().toString();
At this point, I can get some values for ID.Number but I am not able to retrieving any information for the value Custom_SFDCChangeReqID2.
When I run the restful query to retrieve information using a browser from a server standpoint it works and it does retrieve the information I am looking for. I used this syntax:
https://.../rest-1.v1/Data/Story?sel=Number,ID,Story.Requests.Custom_SFDCChangeReqID2,Story.
Alex: Remember that Results is an array of Asset´s, so I guess you should be accessing the information using something like
String RequestCRID= results[0].getAttribute(requestCRIDAttribute).getValue().toString();
String IdNumber= results[0].getAttribute(idNumberAttribute).getValue().toString();
or Iterate through the array.
Also notice that you have defined:
Asset[] results and not result
Hi thanks for your answer! I completely forgot about representing the loop, I was too focus on the retriving information part, yes I was actually using a loop and yes I created a temporary variable to check what I was getting from the query in the form
Because I was getting the variables one by one so I was only using the first record. My code works after all. It was just that What I was querying didn't contain any information of my use, that's why I was not finding any. Anyway thanks for your comment and observations
Somehow I couldn't find the answer to this.
I am running a query to parse.com and want to download all of the rows that contain an empty value in one of my columns.
ParseQuery<ParseObject> query = ParseQuery.getQuery(Constants.myTestTable);
query.whereEqualTo("MyColumn", "");
When I upload a csv to parse where MyColumn does not have any value the column cells on parse show "(undefined)" and I cannot retrieve the data. However, when I delete all content in the cell I am able to retrieve it. I want to be able to retrieve the data if the cell has the default "(undefined)" value from parse. I tried...
ParseQuery<ParseObject> query = ParseQuery.getQuery(Constants.myTestTable);
query.whereEqualTo("MyColumn", null);
But that did not work either. I'm sure there is an easy solution to this, I just can't get the dang thing to work.
What you want are whereExists and whereDoesNotExist.
query.whereDoesNotExist("MyColumn");