Search code examples
javamongodb-javamongo-java

How to get the results as a value



I am trying to make a program that finds the coordinate values x and y from the database of mongoDB. After,to subtract these values to find every time their various and to search for the position of the new coordinate.

The structure of the results is for example: offscreen(count): { "x" : "1248" , "y" : "698"}

I have done something but i do not know how to give the values for (x2,x1,y2,y1) or it has better solutions for that.

Thanks for help..

            int x_and_y = 1;

            while (cursorEvents.hasNext()) {
            DBObject documentInEventCollection = cursorEvents.next();

            if("mouseMove".equals(documentInEventCollection.get("type"))){ 

            System.out.println("offscreen(" + x_and_y + "): " + documentInEventCollection.get("offScreen").toString());
            x_and_y++;                                      
            }

            if("mouseMove".equals(documentInEventCollection.get("type"))){ 

                if((x2 - x1) < 0 ){

                    System.out.println("Right");

                }else {

                    System.out.println("Left");
                }
                if((y2 - y1) > 0 ){

                    System.out.println("Down");

                }else{

                    System.out.println("Up");                       
                }
            }

Solution

  • You could tried to replace your loop while by this :

      while (cursorEvents.hasNext()) 
      {
            DBObject doc1 = cursorEvents.next();
            if(cursorEvents.hasNext())
            {
                DBObject doc2 = cursorEvents.next();
            }
    
            if("mouseMove".equals(documentInEventCollection.get("type"))){ 
    
            System.out.println("offscreen(" + x_and_y + "): " + doc1.get("offScreen").toString()+","+doc2.get("offScreen").toString());
            x_and_y++;                                      
            }