Using Binary Data datetype for storing byte arrays in mongoDB
来源:互联网 发布:波士顿动力 知乎 编辑:程序博客网 时间:2024/05/29 01:53
Store GUIDs as BinData, rather than as strings
BSON includes a binary data datatype for storing byte arrays. Using this will make the id values, and their respective keys in the _id index, twice as small.
Note that unlike the BSON Object ID type (see above), most UUIDs do not have a rough ascending order, which creates additional caching needs for their index.
根据官网文档,以byte arrays的方式存储数据,特别是_id,能减少索引大小,提高效率,不过没有验证。目前的Java Driver对此支持好像不是很好,其Binary类可以把数据存入mongodb,但是读取字段时却不能进行强制转换回来。
String t = "123456789abcdef9";Binary id = new Binary(t.getBytes());
BasicDBObject obj = new BasicDBObject();
obj.append("_id", id).append("name", "me");
coll.insert(obj);System.out.println(coll.find(obj).explain());
DBCursor cursor = coll.find(obj);
while(cursor.hasNext())
{
DBObject o = cursor.next();
System.out.println(o);
Binary b = (Binary) o.get("_id"); // won't work, will get Exception when doing data type convertion
System.out.println(new String((byte[])o.get("_id"))); // this way works well
// System.out.println(k);
}
- Using Binary Data datetype for storing byte arrays in mongoDB
- Storing data in browser
- How do I use MySQL C++ Connector for storing binary data?
- Store binary data to MySQL using escape_string in MySQLdb
- Storing UTF-8 data in VARCHAR or NVARCHAR?
- Storing and Searching for Data 数据存储和搜索
- android-Storing and Searching for Data,Remaining Backward Compatible
- For those interested in storing components onto a stream
- Storing debug log for failure in /tmp/tmpCCjLum
- Spring Data for Mongodb
- Using a Range for with Multdimensional Arrays.
- Storing Big Data with HBase
- Use Cases > Storing Log Data
- User Secrets – Storing sensitive data in ASP.NET Core projects
- Data Structures & Algorithms in Java ---- Arrays
- Reading binary data in C#
- Reading binary data in C#
- data-binary parameter in cURL
- SQL中DateTime转换成Varchar样式
- IE的event.srcElement和Firefox的event.target
- 注解的力量 -----Spring 2.5 JPA hibernate 使用方法的点滴整理(三):通过 @Autowired的使用来消除 set ,get方法。
- 软件测试从零开始
- GDB Tips
- Using Binary Data datetype for storing byte arrays in mongoDB
- 注解的力量 -----Spring 2.5 JPA hibernate 使用方法的点滴整理(四):使用 命名空间 简化配置
- 寻回犬:笔记本、智能手机守护者
- Asp.net查询数据库
- 【模电】放大电路之频率响应
- AndroidManifest.xml文件剖析
- 注解的力量 -----Spring 2.5 JPA hibernate 使用方法的点滴整理(五):使用@Component 来简化bean的配置
- 注解的力量 -----Spring 2.5 JPA hibernate 使用方法的点滴整理(六): 一些常用的数据库 注解
- java取消科学计数法