Package org.bson

Examples of org.bson.BSONObject.keySet()


            return asDBObject(asDBKey(expr, 0), "");

        } else if (op == Ops.AND) {
            BSONObject lhs = (BSONObject) handle(expr.getArg(0));
            BSONObject rhs = (BSONObject) handle(expr.getArg(1));
            if (Sets.intersection(lhs.keySet(), rhs.keySet()).isEmpty()) {
                lhs.putAll(rhs);
                return lhs;
            } else {
                BasicDBList list = new BasicDBList();
                list.add(handle(expr.getArg(0)));
View Full Code Here


    data: for (Object o : BSONUtils.values(bucket, "FormPost.data")) {
      BSONObject upload = (BSONObject) o;
      for (Object f : BSONUtils.values(upload, "files")) {
        BSONObject bf = (BSONObject) f;
        for (String fn : bf.keySet()) {
          BSONObject x = (BSONObject) bf.get(fn);
          byte[] theSha = getSha(x);
          if (Arrays.equals(theSha, sha)) {
            file = x;
            break data;
View Full Code Here

        if ("_id".equals(field)) {
          id = command.get(field);
          if (id instanceof BSONObject) {
            BSONObject options = (BSONObject) id;

            for (String s : options.keySet()) {
              if (s.equals("$ref") || s.equals("$id"))
                continue;
              if (QueryOperators.GT.equals(s)) {
                multiPut(filters, field, new GreaterThan(
                    options.get(s)));
View Full Code Here

              || value instanceof Boolean) {
            multiPut(filters, field,
                new Equality(new Object[] { value }));
          } else if (value instanceof BSONObject) {
            BSONObject options = (BSONObject) value;
            for (String f : options.keySet()) {
              if ("$in".equals(f)) {
                multiPut(filters, field, new Equality(BSONUtils
                    .values(options, f)));
              } else if (QueryOperators.GT.equals(f)) {
                multiPut(filters, field, new GreaterThan(
View Full Code Here

    if (o1 instanceof BSONObject) {
      // compare key-value-key-value-... in order
      BSONObject b1 = (BSONObject) o1;
      BSONObject b2 = (BSONObject) o2;
      List<String> keys1 = new ArrayList<String>(b1.keySet());
      List<String> keys2 = new ArrayList<String>(b2.keySet());
      int m = Math.min(keys1.size(), keys2.size());
      for (int i = 0; i < m; i++) {
        // key
        String k1 = keys1.get(i);
        String k2 = keys2.get(i);
View Full Code Here

      String fc = query.getFullCollectionName();
      String[] db = fc.split("\\.", 2);

      if ("$cmd".equals(db[1])) {
        BSONObject command = query.getQuery();
        String c = command.keySet().iterator().next();
        CommandHandler handler = commands.get(c);
        if (handler != null) {
          BSONObject result = handler.handleCommand(db[0], command);
          e.getChannel().write(
              ReplyMessage.reply((Message) e.getMessage(), 0, 0,
View Full Code Here

      if (hasModifier) {
        for (String op : update.keySet()) {
          if ("$set".equals(op)) {
            BSONObject $set = (BSONObject) update.get("$set");
            for (String k : $set.keySet()) {
              // if _id is present, it must match
              if ("_id".equals(k))
                if (!_id.equals($set.get(k)))
                  throw new UnsupportedOperationException(
                      "cannot change _id of a document");
View Full Code Here

                    "nested fields not implemented");
              t.put(k, $set.get(k));
            }
          } else if ("$addToSet".equals(op)) {
            BSONObject $set = (BSONObject) update.get("$addToSet");
            for (String k : $set.keySet()) {
              Object x = $set.get(k);
              if (x instanceof BSONObject) {
                BSONObject b = (BSONObject) x;
                if (b.containsField("$each")) {
                  for (Object each : BSONUtils.values(b,
View Full Code Here

        assertEquals( "horowitz" , read.get( "eliot" ).toString() );
        assertEquals( 517.3 , ((Double)read.get( "num" )).doubleValue(), .01 );
        assertEquals( "b" , ((BSONObject)read.get( "next" ) ).get( "a" ).toString() );
        assertEquals( "a" , ((BSONObject)read.get( "next" ) ).get( "b" ).toString() );
        assertEquals( "y" , read.get( "z" ).toString() );
        assertEquals( o.keySet().size() , read.keySet().size() );

    }

    @Test
    public void testArray1(){
View Full Code Here

        BSONObject read = BSON.decode( BSON.encode( o ) );
       
        assertEquals( "horowitz" , read.get( "eliot" ).toString() );
        assertEquals( 517 , ((Integer)read.get( "num" )).intValue() );
        assertEquals( "y" , read.get( "z" ).toString() );
        assertEquals( o.keySet().size() , read.keySet().size() );
        assertEquals( 3 , a.size() );
        assertEquals( a.size() , ((List)read.get( "a" ) ).size() );
        assertEquals( "A" , ((List)read.get( "a" ) ).get( 0 ).toString() );
        assertEquals( "B" , ((List)read.get( "a" ) ).get( 1 ).toString() );
        assertEquals( "C" , ((List)read.get( "a" ) ).get( 2 ).toString() );
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.