2

I am new to android and mongodb. I have problem with inserting data to my mLab database using my android application. My code is this:

final class MongoLabSaveData extends AsyncTask<Object, Void, Boolean> {
    @Override
    protected Boolean doInBackground(Object... params) {

        SignupData signupData = (SignupData) params[0];
        Log.d("Sign_Up", ""+signupData);

        try {
            SupportDataAPI sd = new SupportDataAPI();
            URL url = new URL(sd.buildSignupSaveURL());

            HttpURLConnection connection = (HttpURLConnection) url
                    .openConnection();
            connection.setRequestMethod("PUT");
            connection.setDoOutput(true);
            connection.setRequestProperty("Content-Type",
                    "application/json");
            connection.setRequestProperty("Accept", "application/json");

            OutputStreamWriter osw = new OutputStreamWriter(connection.getOutputStream());

            osw.append(sd.createSignupData(signupData));
            osw.flush();
            osw.close();

            if(connection.getResponseCode() <205)
            {
                return true;
            }
            else
            {
                return false;
            }

        } catch (Exception e) {
            e.getMessage();
            Log.d("Got error", e.getMessage());
            return false;
        }
    }
}

Here, the data gets inserted to every 0th index of json data due to this line:

SignupData signupData = (SignupData) params[0];

How can I make this in such a way that it appends my json data with the existing data. Not in the 0th index.

Himanshu Jain
  • 334
  • 2
  • 12

0 Answers0