简体   繁体   English

MongoDB Java驱动程序-对象类型

[英]MongoDB Java driver - Object types

I need to use the MongoDB Java drive since I need to use the driver within Matlab. 我需要使用MongoDB Java驱动器,因为我需要在Matlab中使用该驱动器。

At the moment I have the followed problem. 目前,我有以下问题。 I get my BSON object from database, now I need to convert the BSON tree into a Matlab structure. 我从数据库中获取了BSON对象,现在我需要将BSON树转换为Matlab结构。 My problem is that the BSONObject or BasisBSONObject class does not have a function to retrieve the type of the particluar BSON object (ARRAY, OBJECTID, ...). 我的问题是BSONObject或BasisBSONObject类没有函数来检索特定BSON对象的类型(ARRAY,OBJECTID等)。 There is a class named BSON in the java driver that defines the values I need. Java驱动程序中有一个名为BSON的类,用于定义我需要的值。 But I do not know how to find out what type my current BSON object is. 但是我不知道如何找出当前BSON对象的类型。

The C++ driver and also the C# driver has a function that returns the type of a particular BSON element, but where is it in the JAVA driver. C ++驱动程序以及C#驱动程序都有一个函数,该函数返回特定BSON元素的类型,但是它在JAVA驱动程序中的位置。

Any advices are welcome. 欢迎任何建议。 I'm not oerfect in JAVA maybe I did not find it for this reason...? 我在JAVA中并不完美,也许因为这个原因我没有找到它?

Why not get the object and call getClass() on it? 为什么不获取对象并对其调用getClass() myBSON.get("myKey").getClass() Seems like that is just as easy as calling some myBSON.getTypeOf("myKey") method that does not exist and would also be redundant in the API. myBSON.get("myKey").getClass()就像调用某些不存在且在API中也是多余的myBSON.getTypeOf("myKey")方法一样简单。

Typically I use BSON<->Java POJO mapping libraries like Morphia or Spring-Data-Mongo. 通常,我使用Morson或Spring-Data-Mongo之类的BSON <-> Java POJO映射库。 These libraries have converters that can convert to and from mongo objects to type-safe objects. 这些库具有可在mongo对象与类型安全对象之间来回转换的转换器。

Additionally, I think the Mongo 3.x driver is suppose to have better support for this. 另外,我认为Mongo 3.x驱动程序应该对此有更好的支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM