Cannot update the column information in table parse.com - android

I have a table lets call "Post" which has 3 columns "UserA"<ParseUser>, "UserB" and "Status"<String>.
Data consists of UserA currentUser, UserB another ParseUser, status => A
When I am going to update the status from "A" to "B" it throw me error
com.parse.ParseException: java.lang.IllegalArgumentException: Cannot save a ParseUser that is not authenticated.
Can anyone help me please?

You need to be logged in as the user you're trying to modify. A possible solution would be to call a Cloud Code function and use the Master Key to do this.
The Cloud Code guide is here: https://parse.com/docs/cloud_code_guide

You should add below code to let afterSave / beforeSave hooks know that you are updating table directly.
if (request.master) {
Parse.Cloud.useMasterKey();
}

Related

Fetching Object value in mongodb through query

I am making a chat app through socket.io in Android through Node.js . I want to store history of message and username which I have already stored successfully in mongodb but I want to fetch message:Object values here.. can someone please help me in writing query.
This query results in the output which you can see in the image.
messagesCollection.find().toArray().then(function (docs){
console.log(JSON.stringify(docs))
I want to retrieve "message" & "senderNickname" value through query. Replies are highly appreciated.
Pass projection operators in a query,
messagesCollection.find({},{_id: 0, "message.message":1,"message.senderNickname":1})
.toArray().then(function (docs){console.log(JSON.stringify(docs))});
make _id: 1 if you want object id as well for each record.

How to Create Login query with android orm?

I need to create a login page with Android Studio and my question is how to
create login query with Suger ORM? Please answer me just with orm (netter answer me with Suger ORM but is not different in other orms) because I know how to create login query with SQLite database. Thanks everyone and sorry for bad English :)
Suger.findWithQuery(User.class, "SELECT user_name and password from suger where " + "user_name= ? AND password= ?", name, pass);
This my Code!!!
i create Method and my Method return The true;
i sayd in clicklistener button if this method return a true Toast to me (Successful) else sayd to me show Failed!!
But is my problem its is always for any typing in edit text The Toast is show successful !!!!
the field name and pass i get the text from two edit text
Welcome to SO, Ali!
Since you have not provided enough information about your question I'm going to assume that you are familiar with android enough to create an activity, having two edittext in it and a login button,
so on the onClickListener event of the login button you need to query your database for the provided Login info (say email address as user name). following snippet is a simple way to query a table in Sugar Orm
List<User> users = User.findWithQuery(User.class,"SELECT * FROM USER WHERE email = ?",email);
obviously users may have zero length which means no user exists with this email or one member which is your user, now you need to verify the password, preferably stored using a hash algorithm.
moreover, I would like to mention Android Room which is a component from Android Arch Components , an orm designed by Android team which is simpler than other ORMs and have great benefits such as being Lifecycle aware.

How can I store the opened room's chat at unique locations in Firebase and then retrieve them?

I want to do something like this: suppose there are 5 chat rooms and the user can enter and chat in any chat room by pressing the respective button. So, he should be shown the chats of that room only and not overall chat. At what reference in the Firebase Database do these chats should be stored so that every time when user enters a room, he is shown only that room's chat?
One way I thought is by generating timestamp and storing the chat under it in Firebase Database and then fetching the chats from there, but when I'm trying to this a new timestamp is getting generated every time and the previous one under which chats are stored in the database is getting lost.
Here's how I'm generating the timestamp:
Long tsLong = System.currentTimeMillis()/1000;
String ts = tsLong.toString();
Here's how I'm storing chat under it:
mFirebaseDatabaseReference.child("chatmodel").child(ts).setValue(model);
How do I achieve this? Please help me.
To achieve this I would suggest you to re-structure your database. Avoid too much nesting and post the chat rooms/chat requests like this:
So here you see two chat rooms under unique ids generated by .push() at the time of posting request. With one unique identifier for request with key uniqueCharacter.
{
"-HFSSFG5647DDHD" : {
"name" : "Some Name",
"someOtherinfo" : "test",
"timestamp" : 12443567,
"uniqueCharacter" : "Request2"
},
"-YYTH6637FRFSHt5" : {
"name" : "Some other name",
"someOtherinfo" : "test",
"timestamp" : 12443567,
"uniqueCharacter" : "Request3"
}
}
Now the other user sees both these requests and once he clicks on some you get the unique id generated at the time of pushing and create a separate chat room for that particular push id using filters like this:
If user selected request3 then your database ref will be:
databaseRef.orderByChild("uniqueCharacter").equalTo("Request3");
This will give you access to that particular push id which you can share among all those who chose this and create a common chat room with same id for all of them.
Hope you get the basic idea here on achieving what you want.
This is not a production example but just a basic one to give you an idea about better way of achieving your goal.

Android Parse query for data from more than two tables

I am using Parse for one of my android application and struggling for a query to get output.
Application Parse DB has three table which is as described below-
User: user related information with unique object Id
Post: Contains Post related information with unique object Id and UserId(Pointer to user table) who create the post
Like: UserId(Pointer to user table) represent who is Liking the post, PostId(Pointer to post table) which post is liking and unique
object Id
Now I want to make a single compound query for All post for a specific user along-with total number of likes to corresponding post. Please suggest a solution/query for that
When a user creates a post, assign the user objectID to some post identifier property in the post table.
To retrieve all posts from a user, a query like this may help:
query.whereEqualTo("objectID", currentUser.objectID)
If you're just concerned about the like count, rather than each user who has liked the post, you may want to have an Integer value in the post table that is incremented after a user presses the like button on that post.
You should create your own webHook.
Following this exemples here you can easily learn and develop your own stuff, you can even add some triggers to your application!
https://parse.com/docs/cloudcode/guide#cloud-code-cloud-functions
https://parse.com/docs/cloudcode/guide#cloud-code-beforesave-triggers
If User table doesn't have Post<.Relation> column
I suggest you to read about how to join queries.
f.g. make a query1 to get the user, then another query2 to get all posts with whereMatchesQuery('UserColumnInPostTable', query1) function.
Now, you are going to get all posts of a specific user efficiently.
.
If User table have Post<.Relation> column
this is the easiest way
Just get the user object and get the relation object, then get the query, and find in background

How to retrieve current user data using parse sdk in android?

The goal is : after a user has been logged in , the next activity should display his list of courses.
There is a table of courses in Parse's cloud, but how can I retrieve the correct courses (current user's courses) ?
I've thought of 2 approaches :
1. using getCurrentUser method - but what if there are more than one user in the cache ?
2. save for each course the userName that saved it , and then query for that userName - but how should I know that the currentUser method will return the correct user ?
How can I solve this problem ?
using getCurrentUser method - but what if there are more than one user in the cache ?
There's always one currently logged in user and ParseUser.getCurrentUser() will get it. Well, unless there is no logged in user.
but how should I know that the currentUser method will return the correct user
As above. I don't get what you're confused about.
There is a table of courses in Parse's cloud, but how can I retrieve the correct courses (current user's courses)
and
save for each course the userName that saved it , and then query for that userName - but how should I know that the currentUser method will return the correct user ?
I can think of two approaches here. There may be more. Up to you what you decide to use.
So you have the _User table and the Course table. You can do one of the following:
Add a courses array to each _User and for each _User, store their list of courses there. It should be a list of objectIds, so basically you'll have the ID's of all the courses that _User is registered for. Each Parse object has a limited size in the database so you should use it if you are sure you won't need big amounts of data for each user. If you want to retrieve this, query the _User table by the id of the user and fetch the list of courses.
The "relational" approach: add an UserCourse table that has a userId and a courseId column. Every time you want to add a course for a particular user, you add a new entry in here that holds the id of that user and the id o the course. Similarly to the above, have a query that fetches all the stuff from UserCourse by userId. Note that in this case you'll also need to make sure your query fetches the data from _User and Course. Otherwise you'll just end up with UserCourse entries, which merely store ID's.

Categories

Resources