How to Start SequoiaDB

Basic Operation

Data Model

Database Management








Release Note


  • Content
  • Comments
  • History

Java BSON Usage

Java BSON data type

SequoiaDB supports various BSON data type.

Java BSON Structured Data Type

  • Integer/Float

    Java BSON structured integer/float type:
    // {a:123, b:3.14}
    BSONObject obj = new BasicBSONObject();
    obj.put("a", 123);
    obj.put("b", 3.14);
  • String

    Java BSON structured string type:
    // {a:"hi"}
    BSONObject obj = new BasicBSONObject();
    obj.put("a", "hi");
  • null

    Java BSON structured null type:
    // {a:null}
    BSONObject obj = new BasicBSONObject();
    obj.put("a", null);
  • object

    Java BSON structured nested object type:
    // {b:{a:1}}
    BSONObject subObj = new BasicBSONObject();
    subObj.put("a", 1);
    BSONObject obj = new BasicBSONObject();
    obj.put("b", subObj);
  • array

    Java BSON uses org.bson.types/BasicBSONList to structure the array type:
    // {a:[0,1,2]}
    BSONObject obj = new BasicBSONObject();
    BSONObject arr = new BasicBSONList();
    arr.put("0", 0);
    arr.put("1", 1);
    arr.put("2", 2);
    obj.put("a", arr);
  • Boolean

    Java BSON structured boolean type:
    // {a:true, b:false}
    BSONObject obj = new BasicBSONObject();
    obj.put("a", true);
    obj.put("b", false);
  • object ID

    Java BSON uses org.bson.types.ObjectId to generate the value of each "_id" field. Java BSON's ObjectID is 12 bits long which is a little different from the ObjectID introduced in Database Concept-Databse-Document-ObjectID section, currently, the 12 bits of a Java ObjectId are composed of three parts: 4 bits for a timestamp accurate to milliseconds, 4 bits for the identification of the system (physical machine).
    BSONObject obj = new BasicBSONObject();
    ObjectId id1 = new ObjectId();
    ObjectId id2 = new ObjectId("53bb5667c5d061d6f579d0bb");
    obj.put("_id", id1);
  • regex

    Java Bson uses java.util.regex.Pattern to structure the regex data type.
    BSONObject matcher = new BasicBSONObject();
    Pattern obj = Pattern.compile("^2001",Pattern.CASE_INSENSITIVE);
    matcher.put("serial_num", obj);
    BSONObject modifier = new BasicBSONObject("$set", new BasicBSONObject("count",1000));
    cl.update(matcher, modifier, null);
    The above regex structures a matching condition; it modifies the value of the “count” field of all the records with a serial number that starts with 2001 into 1000. Note: The above uses Pattern to structure the bson matcher, but if using matcher.toString(), the content will be:
    { "serial_num" : { "$options" : "i" , "$regex" : "^2001"}}
    To get the same content by following bson constructed:
    BSONObject matcher2 = new BasicBSONObject();
    BSONObject obj2 = new BasicBSONObject();
    matcher2.put("serial_num", obj2);
    But matcher2 structured in the latter way is a common nested type instead of a regex.
  • Date

    Java BSON uses java.util.Date to structure the date type:
    BSONObject obj = new BasicBSONObject();
    Date now = new Date();
    obj.put("date", now);
  • Binary

    Java BSON uses java.util.type.Binary to structure the binary type:
    BSONObject obj = new BasicBSONObject();
    String str = "hello world";
    byte[] arr = str.getBytes();
    Binary bindata = new Binary(arr);
    obj.put("bindata", bindata);
  • TimeStamp

    Java BSON uses org.bson.types.BSONTimestamp to structre the time stamp type:
    int sec = 1404189030 ; // 2014-07-01 12:30:30
    BSONObject obj = new BasicBSONObject();
    BSONTimestamp ts = new BSONTimestamp(sec, 0);
    obj.put("timestamp", ts);
please login to comment.
Latest Comment
  • 2015-03-14

About Us

SequoiaDB is a financial-level distributed database vendor and is the first Chinese database listed in Gartner’s Magic Quadrant OPDBMS report. SequoiaDB has recently released version 3.0.
SequoiaDB is now penetrating the vertical sector Financial Industry quickly and had more than 50 banking clients and hundreds of enterprise customers in industries including government, telecommunication, Internet and IoT.

Tower R, No.8 North Star East Road, Chaoyang District, Beijing,China
Tower A, No.22 Qinglan Street, Panyu District, Guangzhou,China
Tsing Hua Tech Park, Nanshan District, Shenzhen,China