Package jp.ameba.mongo.protocol

Examples of jp.ameba.mongo.protocol.Insert


   
    client.delete(new Delete("test", "insert", new BasicBSONObject("_id", 1)));
   
    // insert new document
    client.insert(
        new Insert("test", "insert",
          new BasicBSONObject("_id", 1)
            .append("name", "test-name")
            .append("integer", 100)
            .append("long", 1000L)
            .append("binary", "test binary".getBytes())
    ));

    // find
    Query query = new Query("test", "insert", 0, 1, new BasicBSONObject("_id", 1), null);
    Response response = client.query(query);
    Assert.assertNotNull(response);
    Assert.assertEquals(1, response.getNumberReturned());
    Assert.assertEquals(0, response.getStartingFrom());
    Assert.assertEquals(query.getWaitingRequestId(), response.getHeader().getResponseTo());
   
    BSONObject resultObject = response.getDocuments().get(0);
    Assert.assertEquals(1, resultObject.get("_id"));
    Assert.assertEquals("test-name", resultObject.get("name"));
    Assert.assertEquals(100, resultObject.get("integer"));
    Assert.assertEquals(1000L, resultObject.get("long"));
    Assert.assertArrayEquals("test binary".getBytes(), (byte[]) resultObject.get("binary"));
   
    // Duplicate error
    MongoException me = null;
    try {
      client.insert(
          new Insert("test", "insert",
              new BasicBSONObject("_id", 1)
                .append("name", "test-name2")
          )
      );
    } catch (MongoException e) {
View Full Code Here


    Assert.assertEquals(0.0, result.get("n"));
   
    // prepare data
    for (int i = 0; i < 100; i++) {
      BSONObject doc = createObject(i);
      client.insert(new Insert("test", "testQuery", doc));
    }
  }
View Full Code Here

        new BasicBSONObject("name", "abcdefg")
    ));
    Response response = client.query(new Query("test", "update", 0, 1, new BasicBSONObject("_id", "updateId"), null));
    Assert.assertEquals(response.getNumberReturned(), 0);

    client.insert(new Insert("test", "update", new BasicBSONObject("_id", "updateId").append("name", "testname")));
    response = client.query(new Query("test", "update", 0, 1, new BasicBSONObject("_id", "updateId"), null));
    Assert.assertEquals(1, response.getNumberReturned());
   
    client.update(new Update("test", "update", new BasicBSONObject("_id", "updateId"), new BasicBSONObject("_id", "updateId").append("name", "testname updated")));
    response = client.query(new Query("test", "update", 0, 1, new BasicBSONObject("_id", "updateId"), null));
View Full Code Here

    insert(document, defaultConsistency);
  }

  @Override
  public void insert(BSONObject document, Consistency consistency) {
    client.getConnection().insert(new Insert(
        databaseName,
        collectionName,
        document
    ).consistency(consistency));
  }
View Full Code Here

    insert(documents, defaultConsistency);
  }

  @Override
  public void insert(BSONObject[] documents, Consistency consistency) {
    client.getConnection().insert(new Insert(
        databaseName,
        collectionName,
        Arrays.asList(documents)
    ).consistency(consistency));
  }
View Full Code Here

      .append("ns", fullName)
      .append("name", indexName)
    ;

    client.getConnection().insert(
        new Insert(
            databaseName,
            "system.indexes",
            doc
        ).consistency(consistency)
    );
View Full Code Here

TOP

Related Classes of jp.ameba.mongo.protocol.Insert

Copyright © 2018 www.massapicom. 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.