Example usage for com.mongodb BasicDBList BasicDBList

List of usage examples for com.mongodb BasicDBList BasicDBList

Introduction

In this page you can find the example usage for com.mongodb BasicDBList BasicDBList.

Prototype

BasicDBList

Source Link

Usage

From source file:org.jongo.query.BsonQueryFactory.java

License:Apache License

private DBObject marshallCollection(Collection<?> parameters) {
    BasicDBList list = new BasicDBList();
    for (Object param : parameters) {
        list.add(marshallParameter(param));
    }//  w  w  w  . j  ava  2s . co m
    return list;
}

From source file:org.jwebsocket.watchdog.test.WatchDogTask.java

License:Open Source License

@Override
public DBObject asDocument() {
    BasicDBObject obj = new BasicDBObject();
    obj.put("id", getId());
    obj.put("everyNMinutes", getEveryNMinutes());
    obj.put("everyNHours", getEveryNHours());
    obj.put("everyNDays", getEveryNDays());
    obj.put("frequency", getType());
    obj.put("lastExecution", getLastExecution());

    BasicDBList lList = new BasicDBList();

    for (IWatchDogTest t : getTests()) {
        lList.add(t.getId());//  w ww .jav  a  2s  . c  o  m
    }

    obj.put("idTests", lList);

    return obj;
}

From source file:org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoDaoUtil.java

License:Apache License

/**
 * Specific method for recursive substitute the reserved $ and . characters
 * in the key names of the DBObject./*from  w  ww  . j  a v  a  2  s.  co m*/
 *
 * @param profileBody the profileBody
 * @return encoded DBObject
 */
public static DBObject encodeReservedCharacteres(DBObject profileBody) {
    if (profileBody == null) {
        return null;
    }
    if (profileBody instanceof BasicDBList) {
        BasicDBList dbList = (BasicDBList) profileBody;
        BasicDBList modifiedList = new BasicDBList();
        for (Object value : dbList) {
            if (value instanceof DBObject) {
                modifiedList.add(encodeReservedCharacteres((DBObject) value));
            } else {
                modifiedList.add(value);
            }
        }
        return modifiedList;
    } else {
        Set<String> keySet = profileBody.keySet();
        DBObject modifiedNode = new BasicDBObject();
        if (keySet != null) {
            for (String key : keySet) {
                Object value = profileBody.get(key);
                for (char symbolToReplace : RESERVED_CHARACTERS.keySet()) {
                    key = key.replace(symbolToReplace, RESERVED_CHARACTERS.get(symbolToReplace));
                }
                if (value instanceof DBObject) {
                    modifiedNode.put(key, encodeReservedCharacteres((DBObject) value));
                } else {
                    modifiedNode.put(key, value);
                }
            }
        }
        return modifiedNode;
    }
}

From source file:org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoDaoUtil.java

License:Apache License

/**
 * Specific method for recursive decoding the reserved $ and . characters in the key names of the
 * DBObject.//from w ww. ja  v  a  2s .c om
 *
 * @param profileBody the profileBody
 * @return decoded DBObject
 */
public static DBObject decodeReservedCharacteres(DBObject profileBody) {

    if (profileBody == null) {
        return null;
    }
    if (profileBody instanceof BasicDBList) {
        BasicDBList dbList = (BasicDBList) profileBody;
        BasicDBList modifiedList = new BasicDBList();
        for (Object value : dbList) {
            if (value instanceof DBObject) {
                modifiedList.add(decodeReservedCharacteres((DBObject) value));
            } else {
                modifiedList.add(value);
            }
        }
        return modifiedList;
    } else {
        Set<String> keySet = profileBody.keySet();
        DBObject modifiedNode = new BasicDBObject();
        if (keySet != null) {
            for (String key : keySet) {
                Object value = profileBody.get(key);
                for (char symbolToReplace : RESERVED_CHARACTERS.values()) {
                    key = key.replace(symbolToReplace, RESERVED_CHARACTERS.inverse().get(symbolToReplace));
                }
                if (value instanceof DBObject) {
                    modifiedNode.put(key, decodeReservedCharacteres((DBObject) value));
                } else {
                    modifiedNode.put(key, value);
                }
            }
        }
        return modifiedNode;
    }
}

From source file:org.keycloak.connections.mongo.updater.impl.updates.Update1_8_0.java

License:Apache License

@Override
public void update(KeycloakSession session) {
    BasicDBList orArgs = new BasicDBList();
    orArgs.add(new BasicDBObject("type", UserCredentialModel.PASSWORD));
    orArgs.add(new BasicDBObject("type", UserCredentialModel.PASSWORD_HISTORY));

    BasicDBObject elemMatch = new BasicDBObject("$or", orArgs);
    elemMatch.put("algorithm", new BasicDBObject("$exists", false));

    BasicDBObject query = new BasicDBObject("credentials", new BasicDBObject("$elemMatch", elemMatch));

    BasicDBObject update = new BasicDBObject("$set",
            new BasicDBObject("credentials.$.algorithm", Pbkdf2PasswordHashProvider.ID));

    DBCollection users = db.getCollection("users");

    // Not sure how to do in single query
    int countModified = 1;
    while (countModified > 0) {
        WriteResult wr = users.update(query, update, false, true);
        countModified = wr.getN();/*from   w w  w. j  a  v  a  2  s .  c  om*/
        log.debugf("%d credentials modified in current iteration during upgrade to 1.8", countModified);
    }
}

From source file:org.keycloak.connections.mongo.updater.impl.updates.Update1_9_2.java

License:Apache License

@Override
public void update(KeycloakSession session) {
    BasicDBList orArgs = new BasicDBList();
    orArgs.add(new BasicDBObject("type", UserCredentialModel.PASSWORD));
    orArgs.add(new BasicDBObject("type", UserCredentialModel.PASSWORD_HISTORY));

    BasicDBObject elemMatch = new BasicDBObject("$or", orArgs);
    elemMatch.put("algorithm", HmacOTP.HMAC_SHA1);

    BasicDBObject query = new BasicDBObject("credentials", new BasicDBObject("$elemMatch", elemMatch));

    BasicDBObject update = new BasicDBObject("$set",
            new BasicDBObject("credentials.$.algorithm", Pbkdf2PasswordHashProvider.ID));

    DBCollection users = db.getCollection("users");

    // Not sure how to do in single query
    int countModified = 1;
    while (countModified > 0) {
        WriteResult wr = users.update(query, update, false, true);
        countModified = wr.getN();/*from w w w .  j av  a  2 s.  c o m*/
        log.debugf("%d credentials modified in current iteration during upgrade to 1.8", countModified);
    }
}

From source file:org.kiaan.Main.java

/**
public static class view_main extends JFrame {            
        //from  w w  w .  java  2s.  c  o m
public view_main() throws HeadlessException, IOException {            
    //
            
    addKeyListener(getInputKey());
    //            
    getContentPane();
    setTitle(" ?  ");
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setScreenSize();
//            add BorderLayout
    BorderLayout Layout = new BorderLayout();
    Layout.setHgap(3);Layout.setVgap(3);
    setLayout(Layout);
//        add Top
    JPanel pnlMainTop = new JPanel();
    pnlMainTop.setBackground(Color.LIGHT_GRAY);
    add(pnlMainTop, BorderLayout.PAGE_START);
    JButton btn = new JButton("change");
    pnlMainTop.add(btn);
//        add left
    JPanel pnlMainLeft = new JPanel();
    pnlMainLeft.setBackground(Color.LIGHT_GRAY);
    add(pnlMainLeft, BorderLayout.LINE_START);
//        add right
    JPanel pnlMainRight = new JPanel();
    pnlMainRight.setBackground(Color.LIGHT_GRAY);
    add(pnlMainRight, BorderLayout.LINE_END);
//        add Center
    JPanel pnlMainCenter = new JPanel();
    pnlMainCenter.setBackground(Color.GRAY);
    add(pnlMainCenter, BorderLayout.CENTER);
            
    CardLayout cardLayoutMain = new CardLayout();
    pnlMainCenter.setLayout(cardLayoutMain);
    JPanel subPanelMain = new JPanel(); 
    subPanelMain.setBackground(Color.white);
            
    myToggleButton tb_main = new myToggleButton("",false);            
    subPanelMain.add(tb_main);
            
//            JPanel subPanel2 = new JPanel(); subPanel2.setBackground(Color.blue);
    pnlMainCenter.add(subPanelMain, "1");
//            pnlMainCenter.add(subPanel2, "2");
    btn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
//                    cardLayoutMain.show(pnlMainCenter, "2");
            cardLayoutMain.next(pnlMainCenter);
        }
    });
        
            
//        add Bottom
    JPanel pnlMainBottom = new JPanel();
    pnlMainBottom.setBackground(Color.LIGHT_GRAY);
    add(pnlMainBottom, BorderLayout.PAGE_END);
            
            
            
//            JTable tbl = new JTable();
//            add(tbl, BorderLayout.CENTER);
            
            
            
        
}                            
        
private void setScreenSize() {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setSize(screenSize.width, screenSize.height);
}
}
**/

public static void db() {
    try {
        //connect to db
        MongoClient MongoClient = new MongoClient("localhost", 27017);
        MongoIterable<String> databaseNames = MongoClient.listDatabaseNames();
        //            MongoDatabase kiaanDB = MongoClient.getDatabase("kiaan");            
        //check exists kiaan db
        Boolean blnDBExists = false;
        for (String DBName : databaseNames) {
            if (DBName.equals("kiaan")) {
                blnDBExists = true;
                System.out.println("kiaan database is exists.");
                break;
            }
        }
        if (blnDBExists == false)
            System.out.println("create kiaan database...");
        MongoDatabase mydb = MongoClient.getDatabase("kiaan");
        System.out.println("Connect to database successfully");
        //Check exist user collection
        Boolean blnCollectionName = false;
        for (String collectionName : mydb.listCollectionNames()) {
            if (collectionName.equals("user")) {
                blnCollectionName = true;
                break;
            }
        }
        if (!blnCollectionName) {
            //create users collection
            ObjectId user_id = new ObjectId();
            Document doc = new Document().append("name", "")
                    //.append("credit_limit", 0)
                    //                        .append("status", true)
                    .append("comment", " ? ( ?)")
                    .append("creator_id", user_id).append("users",
                            new Document("_id", user_id).append("id", 1)
                                    .append("first_name", " ")
                                    .append("last_name", "( ? )")
                                    .append("user_name", "admin").append("password", "1602")
                                    //.append("status", false)
                                    .append("creator_id", user_id));
            mydb.getCollection("user").insertOne(doc);
            System.out.println("user collection created...");
            doc.clear();
            //
            BasicDBList dbl = new BasicDBList();
            ObjectId branch_id = new ObjectId();
            dbl.add(new Document("_id", branch_id).append("id", 8561).append("name", " ")
                    .append("city", "").append("creator_id", user_id));
            dbl.add(new Document("_id", new ObjectId()).append("id", 8576).append("name", "")
                    .append("city", "").append("creator_id", user_id));
            ObjectId bank_id = new ObjectId();
            doc = new Document("_id", bank_id).append("name", "")
                    //                        .append("logo", "")
                    .append("creator_id", user_id).append("branches", dbl);
            mydb.getCollection("bank").insertOne(doc);

            dbl = new BasicDBList();
            dbl.add(new Document("_id", new ObjectId()).append("id", 3238).append("name", " ")
                    .append("city", "").append("creator_id", user_id));
            doc = new Document().append("name", "")
                    //                        .append("logo", "")
                    .append("creator_id", user_id).append("branches", dbl);
            mydb.getCollection("bank").insertOne(doc);
            //
            doc = new Document().append("name", "").append("creator_id", user_id).append("branches",
                    new BasicDBList());
            mydb.getCollection("bank").insertOne(doc);
            //add doc to array
            //                DBObject listItem = new BasicDBObject("branches", new BasicDBObject("_id", new ObjectId())
            //                        .append("branch_id",8576)
            //                        .append("name","")
            //                        .append("city","")
            //                );
            //                DBObject findQuery = new BasicDBObject("name", "");
            //                DBObject updateQuery = new BasicDBObject("$push", listItem);
            //                mydb.getCollection("banks").update(findQuery, updateQuery);                                
            //
            System.out.println("bank collection created...");

            //add person
            doc.clear();
            dbl.clear();
            ObjectId person_id1 = new ObjectId();
            ObjectId person_id2 = new ObjectId();
            dbl.add(new Document("_id", person_id1).append("id", 1).append("type", "")
                    .append("first_name", "").append("last_name", "")
                    .append("comment", "     ")
                    .append("creator_id", user_id));

            BasicDBList dbl_tel = new BasicDBList();
            BasicDBList dbl_bankAcc = new BasicDBList();
            dbl_tel.add(new Document("_id", new ObjectId()).append("type", "mobile")
                    .append("number", "09151213139").append("default", true));
            dbl_tel.add(new Document("_id", new ObjectId()).append("type", "mobile").append("number",
                    "09151112233"));
            dbl_tel.add(new Document("_id", new ObjectId()).append("type", "work")
                    .append("number", "05133661313").append("default", true));
            dbl_bankAcc.add(new Document("_id", new ObjectId()).append("type", "bank_acc")
                    .append("bank_id", bank_id).append("number", "4218504285")
                    .append("comment", "  ").append("default", true));
            dbl_bankAcc.add(new Document("_id", new ObjectId()).append("type", "sheba")
                    .append("bank_id", bank_id).append("number", "600120020000004218504285"));
            dbl.add(new Document("_id", person_id2).append("id", 2).append("type", "")
                    .append("first_name", "").append("last_name", "")
                    .append("gender", true).append("credit_limit", 10000000)
                    .append("address",
                            "  -    ?   -  2/716")
                    .append("creator_id", user_id).append("tel", dbl_tel).append("bank_account", dbl_bankAcc));
            doc = new Document("name", "").append("creator_id", user_id).append("persons", dbl);
            mydb.getCollection("person").insertOne(doc);

            mydb.getCollection("person").insertOne(new Document("name", "")
                    .append("creator_id", user_id).append("persons", new BasicDBList()));
            System.out.println("person collection created...");
            //
            doc = new Document("id", 1).append("account_no", "0205575259006")
                    .append("account_holder", "? ").append("bank_id", bank_id)
                    .append("branch_id", branch_id).append("type", 0).append("comment", " ")
                    .append("creator_id", user_id);
            mydb.getCollection("bank_account").insertOne(doc);
            doc = new Document("id", 2).append("account_no", "0207723518008")
                    .append("account_holder", "? ").append("bank_id", bank_id)
                    .append("branch_id", branch_id).append("type", 1).append("creator_id", user_id);
            mydb.getCollection("bank_account").insertOne(doc);

            System.out.println("bank_account collection created...");
            //add units
            ObjectId unit_id = new ObjectId();
            doc = new Document("_id", unit_id).append("name", "").append("creator_id", user_id);
            mydb.getCollection("unit").insertOne(doc);
            System.out.println("Unit collection created...");
            //add products
            dbl = new BasicDBList();
            ObjectId product_id = new ObjectId();
            dbl.add(new Document("_id", product_id).append("id", 1).append("name", "")
                    .append("unit_id", unit_id).append("min_stock", 1000).append("default_price", 8300)
                    .append("comment", " ").append("creator_id", user_id));
            dbl.add(new Document("_id", new ObjectId()).append("id", 2).append("name", "")
                    .append("unit_id", unit_id).append("min_stock", 10).append("default_price", 80000)
                    .append("comment", "  ").append("creator_id", user_id));
            doc = new Document("name", "").append("comment", "  ")
                    .append("creator_id", user_id).append("products", dbl);
            mydb.getCollection("product").insertOne(doc);
            //
            dbl.clear();
            dbl.add(new Document("_id", new ObjectId()).append("id", 3).append("name", "")
                    .append("unit_id", unit_id).append("min_stock", 100).append("default_price", 2500)
                    .append("comment", "   ").append("creator_id", user_id));
            doc = new Document("name", "").append("comment", "   ")
                    .append("creator_id", user_id).append("products", dbl);
            mydb.getCollection("product").insertOne(doc);
            //
            System.out.println("product Document created...");

            //add buy
            doc.clear();
            dbl.clear();
            dbl.add(new Document("_id", new ObjectId()).append("product_id", product_id).append("value", 100)
                    .append("price", 9250).append("comment", "   "));
            dbl.add(new Document("_id", new ObjectId()).append("product_id", product_id).append("value", 350)
                    .append("price", 9350).append("comment", "   "));
            doc = new Document("_id", new ObjectId()).append("type", "buy").append("id", 1)
                    .append("person_id", person_id1).append("by", "? ").append("discount", -1500)
                    //                        .append("increase", 0)
                    .append("tax", 4000)
                    //                        .append("fare", 0)
                    .append("comment", "  ?").append("creator_id", user_id)
                    .append("items", dbl);
            mydb.getCollection("buy").insertOne(doc);
            //                doc.clear(); dbl.clear();
            //                dbl.add(new BasicDBObject("_id",new ObjectId())
            //                        .append("product_id", 1)
            //                        .append("value", 1000)
            //                        .append("price", 9300)                        
            //                );
            //                doc = new BasicDBObject("num", 2)
            //                        .append("date", new Date())                        
            //                        .append("person_id", person_id2)
            //                        .append("by", "? ")
            //                        .append("discount", 0)
            //                        .append("increase", 0)
            //                        .append("user_id", user_id)
            //                        .append("items", dbl);
            //                mydb.getCollection("buy").insert(doc);         
            System.out.println("buy Document created...");

        }

        //            System.out.println("Collection created successfully");
        //            BasicDBObject doc = new BasicDBObject("name","mongoDB");
        //            coll.insert(doc);
    } catch (Exception e) {
        System.err.println(e.getClass().getName() + ": " + e.getMessage());
    }
}

From source file:org.kiaan.Main.java

public static void getBranchesWithProject() {
    try {//w  ww  .  jav  a 2s .  c  o  m
        MongoClient mongoClient = new MongoClient("localhost", 27017);
        DB db = mongoClient.getDB("kiaan");
        DBCollection coll = db.getCollection("banks");
        //            BasicDBObject doc = new BasicDBObject("_id" , false).append("name", true);
        //            BasicDBObject doc1 = new BasicDBObject("name" , "");

        //            BasicDBObject doc = new BasicDBObject("_id" , false).append("branches.name", true);
        //            DBCursor cursor = coll.find(null, doc);

        DBObject unwind = new BasicDBObject("$unwind", "$branches");
        DBObject field = new BasicDBObject("_id", false);
        field.put("name", "$name");
        field.put("branch_id", "$branches.branch_id");
        field.put("branch_name", "$branches.name");
        DBObject project = new BasicDBObject("$project", field);
        DBObject sort = new BasicDBObject("$sort", new BasicDBObject("name", 1));
        List<DBObject> pipeline = Arrays.asList(unwind, project, sort);

        //            AggregationOutput output = coll.aggregate(pipeline);
        //            for (DBObject result : output.results()) {
        //                System.out.println(result);
        //            }

        AggregationOptions aggregationOptions = AggregationOptions.builder().batchSize(100)
                .outputMode(AggregationOptions.OutputMode.CURSOR).allowDiskUse(true).build();

        BasicDBObject dbo = new BasicDBObject();
        BasicDBList dbl = new BasicDBList();
        Cursor cursor = coll.aggregate(pipeline, aggregationOptions);
        while (cursor.hasNext()) {
            dbo = (BasicDBObject) cursor.next();
            System.out.println(dbo.toString());
            //                dbl.add(cursor.next());                
        }
        System.out.println(dbl.toString());

        //            while(cursor.hasNext()) {                  
        //                DBObject obj = cursor.next();               
        //                System.out.println(obj.get("branches"));
        ////                Double first = (Double)obj.get("id");
        ////                String last = (String)obj.get("name");
        ////                ObjectId id = (ObjectId)obj.get("_id");
        ////                model.addRow(new Object[] { id, first, last });
        //            }
        //            tbl.setModel(model);

    } catch (Exception e) {
        System.err.println(e.getClass().getName() + ": " + e.getMessage());
    }

}

From source file:org.kiaan.Main.java

private static void getBuy() {
    try {//from   w  ww  . j a va  2  s  .  c  o  m
        MongoClient mongoClient = new MongoClient("localhost", 27017);
        DB db = mongoClient.getDB("kiaan");
        DBCollection coll = db.getCollection("buy");
        //aggregate
        DBObject unwind = new BasicDBObject("$unwind", "$items");
        //$group            
        DBObject group_id = new BasicDBObject("_id", "$_id");
        group_id.put("num", "$num");
        group_id.put("person_id", "$person_id");
        group_id.put("discount", "$discount");
        group_id.put("increase", "$increase");
        //$group -> $multiply
        BasicDBList args = new BasicDBList();
        args.add("$items.value");
        args.add("$items.price");
        DBObject multiply = new BasicDBObject("$multiply", args);
        //$group -> $sum
        //            DBObject group_sum = new BasicDBObject("$sum", multiply);
        DBObject group_field = new BasicDBObject();
        group_field.put("_id", group_id);
        group_field.put("total", new BasicDBObject("$sum", multiply));
        DBObject group = new BasicDBObject("$group", group_field);
        //$project
        DBObject project_field = new BasicDBObject("_id", "$_id._id");
        project_field.put("person_id", "$_id.person_id");
        project_field.put("num", "$_id.num");
        BasicDBList arr = new BasicDBList();
        arr.add("$total");
        arr.add("$_id.discount");
        arr.add("$_id.increase");
        DBObject field_add = new BasicDBObject("$add", arr);
        project_field.put("sum", field_add);
        DBObject project = new BasicDBObject("$project", project_field);
        DBObject sort = new BasicDBObject("$sort", new BasicDBObject("_id", 1));
        List<DBObject> pipeline = Arrays.asList(unwind, group, project, sort);

        //            AggregationOutput output = coll.aggregate(pipeline);
        //            for (DBObject result : output.results()) {
        //                System.out.println(result);
        //            }

        AggregationOptions aggregationOptions = AggregationOptions.builder().batchSize(100)
                .outputMode(AggregationOptions.OutputMode.CURSOR).allowDiskUse(true).build();

        BasicDBObject dbo = new BasicDBObject();
        BasicDBList dbl = new BasicDBList();
        Cursor cursor = coll.aggregate(pipeline, aggregationOptions);
        //
        DBCollection person_col = db.getCollection("persons");

        //            BasicDBObject query = new BasicDBObject("items.personId",1);             
        BasicDBObject fields = new BasicDBObject("items.$", 1).append("_id", false);

        //            BasicDBList l_per = (BasicDBList) person_col.findOne(query, fields).get("items");
        //            BasicDBObject[] lightArr = l_per.toArray(new BasicDBObject[0]);            
        //            System.out.println(lightArr[0].get("_id"));
        //            System.out.println(lightArr[0].get("first_name"));  

        BasicDBList result = new BasicDBList();
        while (cursor.hasNext()) {
            dbo = (BasicDBObject) cursor.next();
            //                System.out.println(dbo.toString());  
            DBObject query = new BasicDBObject("items._id", (ObjectId) dbo.get("person_id"));
            BasicDBList lst_person = (BasicDBList) person_col.findOne(query, fields).get("items");
            BasicDBObject[] lightArr = lst_person.toArray(new BasicDBObject[0]);
            //                System.out.println(lightArr[0].get("first_name"));

            Date date = ((ObjectId) lightArr[0].get("_id")).getDate();
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            persianCalendar persianCalendar = new persianCalendar(calendar);

            dbo.put("date", persianCalendar.getNumericDateFormatWithTime());
            dbo.put("personId", lightArr[0].get("personId").toString());
            dbo.put("first_name", lightArr[0].get("first_name").toString());
            dbo.put("last_name", lightArr[0].get("last_name").toString());

            dbo.removeField("person_id");
            result.add(dbo);
            //                System.out.println(dbo.get("num"));                  
        }
        System.out.println(result.toString());

    } catch (Exception e) {
        System.err.println(e.getClass().getName() + ": " + e.getMessage());
    }
}

From source file:org.knowrob.knowrob_robcog.MongoRobcogQueries.java

License:Open Source License

public double[] GetActorPoseAt(String actorName, double timestamp) {
    // $and list for querying the $match in the aggregation
    BasicDBList time_and_name = new BasicDBList();

    // add the timestamp and the actor name
    time_and_name.add(new BasicDBObject("timestamp", new BasicDBObject("$lte", timestamp)));
    time_and_name.add(new BasicDBObject("actors.name", actorName));

    // create the pipeline operations, first the $match
    DBObject match_time_and_name = new BasicDBObject("$match", new BasicDBObject("$and", time_and_name));

    // sort the results in descending order on the timestamp (keep most recent result first)
    DBObject sort_desc = new BasicDBObject("$sort", new BasicDBObject("timestamp", -1));

    // $limit the result to 1, we only need one pose
    DBObject limit_result = new BasicDBObject("$limit", 1);

    // $unwind actors in order to output only the queried actor
    DBObject unwind_actors = new BasicDBObject("$unwind", "$actors");

    // $match for the given actor name from the unwinded actors
    DBObject match_actor = new BasicDBObject("$match", new BasicDBObject("actors.name", actorName));

    // build the $projection operation
    DBObject proj_fields = new BasicDBObject("_id", 0);
    proj_fields.put("timestamp", 1);
    proj_fields.put("pos", "$actors.pos");
    proj_fields.put("rot", "$actors.rot");
    DBObject project = new BasicDBObject("$project", proj_fields);

    // run aggregation
    List<DBObject> pipeline = Arrays.asList(match_time_and_name, sort_desc, limit_result, unwind_actors,
            match_actor, project);/*from   w w w . java 2  s.  c o m*/

    AggregationOptions aggregationOptions = AggregationOptions.builder().batchSize(100)
            .outputMode(AggregationOptions.OutputMode.CURSOR).allowDiskUse(true).build();

    // get results
    Cursor cursor = this.MongoRobcogConn.coll.aggregate(pipeline, aggregationOptions);

    // if query has a response, return the pose
    if (cursor.hasNext()) {
        // get the first document as the next cursor and append the metadata to it
        BasicDBObject first_doc = (BasicDBObject) cursor.next();
        // close cursor
        cursor.close();
        // get the pose
        return new double[] { ((BasicDBObject) first_doc.get("pos")).getDouble("x"),
                ((BasicDBObject) first_doc.get("pos")).getDouble("y"),
                ((BasicDBObject) first_doc.get("pos")).getDouble("z"),
                ((BasicDBObject) first_doc.get("rot")).getDouble("w"),
                ((BasicDBObject) first_doc.get("rot")).getDouble("x"),
                ((BasicDBObject) first_doc.get("rot")).getDouble("y"),
                ((BasicDBObject) first_doc.get("rot")).getDouble("z") };
    } else {
        System.out.println("Java - GetActorPose - No results found, returning empty list..");
        return new double[0];
    }
}