Package com.mongodb

Examples of com.mongodb.DBObject.containsField()


        Assert.assertNotNull(indexes);
        Assert.assertEquals(2, indexes.size());
        for (DBObject i : indexes) {
            Assert.assertTrue(i.containsField("key"));
            DBObject key = (DBObject) i.get("key");
            if (key.containsField("indexed")) {
                Object get = key.get("indexed");
                Assert.assertTrue(get instanceof String);
                Assert.assertEquals("2dsphere", get);
                return;
            }
View Full Code Here


                if (cap.count() > 0)
                    dbCapOpts.add("max", cap.count());
                DB db = getDB();
                if (db.getCollectionNames().contains(collName)) {
                    DBObject dbResult = db.command(BasicDBObjectBuilder.start("collstats", collName).get());
                    if (dbResult.containsField("capped")) {
                        // TODO: check the cap options.
                        log.warning("DBCollection already exists is cap'd already; doing nothing. " + dbResult);
                    } else {
                        log.warning("DBCollection already exists with same name(" + collName
                                + ") and is not cap'd; not creating cap'd version!");
View Full Code Here

    HasList hl = new HasList();

    //Test default behavior
    ds.save(hl);
    DBObject dbObj =  ds.getCollection(HasList.class).findOne();
    Assert.assertFalse("field exists, value =" + dbObj.get("names"), dbObj.containsField("names"));

    //Test default storing empty list/array with storeEmpties option
    this.morphia.getMapper().getOptions().storeEmpties = true;
    ds.save(hl);
    dbObj =  ds.getCollection(HasList.class).findOne();
View Full Code Here

    //Test default storing empty list/array with storeEmpties option
    this.morphia.getMapper().getOptions().storeEmpties = true;
    ds.save(hl);
    dbObj =  ds.getCollection(HasList.class).findOne();
    Assert.assertTrue("field missing", dbObj.containsField("names"));

    //Test opposite from above
    this.morphia.getMapper().getOptions().storeEmpties = false;
    ds.save(hl);
    dbObj =  ds.getCollection(HasList.class).findOne();
View Full Code Here

    //Test opposite from above
    this.morphia.getMapper().getOptions().storeEmpties = false;
    ds.save(hl);
    dbObj =  ds.getCollection(HasList.class).findOne();
    Assert.assertFalse("field exists, value =" + dbObj.get("names"), dbObj.containsField("names"));
  }
}
View Full Code Here

            q.or(q.criteria("keywords.keyword").equal("hernandez")));

        Assert.assertEquals(1, q.countAll());
        QueryImpl<PhotoWithKeywords> qi = (QueryImpl<PhotoWithKeywords>)q;
        DBObject realCriteria = qi.prepareCursor().getQuery();
        Assert.assertTrue(realCriteria.containsField("$and"));

    }

    @Test
    public void testFluentAndQuery1() throws Exception {
View Full Code Here

            q.criteria("keywords.keyword").hasAnyOf(Arrays.asList("scott", "hernandez")));

        Assert.assertEquals(1, q.countAll());
        QueryImpl<PhotoWithKeywords> qi = (QueryImpl<PhotoWithKeywords>)q;
        DBObject realCriteria = qi.prepareCursor().getQuery();
        Assert.assertTrue(realCriteria.containsField("$and"));

    }


    @Test
View Full Code Here

                current = (DBObject) current.get(n);
                if (current == null) {
                    break;
                }
            }
            if (current == null || !current.containsField("_c")) {
                // no changes here
                return "";
            } else {
                return current.get("_c").toString();
            }
View Full Code Here

        void append(String path, String changes) {
            DBObject current = doc;
            for (String name : PathUtils.elements(path)) {
                String escName = Utils.escapePropertyName(name);
                if (current.containsField(escName)) {
                    current = (DBObject) current.get(escName);
                } else {
                    BasicDBObject child = new BasicDBObject();
                    current.put(escName, child);
                    current = child;
View Full Code Here

    SimplePOJO pojo = new SimplePOJO();
    pojo.setAnIntegerField(42);

    DBObject document = converter.from(pojo).toDocument();

    assertThat(document.containsField("anIntegerField"), is(true));
    assertThat(document.containsField("_id"), is(true));
    assertThat(document.containsField("aField"), is(false));
    assertThat(document.containsField("anotherField"), is(false));
    assertThat(document.containsField("aLongField"), is(false));
    assertThat(document.containsField("aDoubleField"), is(false));
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.