来自keyValues的MongoDB Java Document.get()用逗号分隔整数(MongoDB Java Document.get() from keyValues holding comma seperated integers)

想象一下名为doc的Document,看起来像这样:

"_id" : ObjectId("56896bbf713dffe8799e0970"), "Section Name" : "BUS-110-01", "Title" : "Business & Entrep. Mindset",, "Building" : "CCM", "Room" : 442, 443, "Days" : "T, TH", "Start Time" : "12:30 PM", "End time" : "1:45 PM",

当我运行String myRoom = doc.getString("Room")我收到一个异常。 我尝试了doc.getInteger("Room")和doc.getDouble("Room")但没有成功,不是我期望的那么多。

如果我创建一个ArrayList<String> Room并运行:

Room.add(doc.get("Room", String.class))我得到java.lang.ClassCastException: Cannot cast java.lang.Integer to java.lang.String

讽刺的是,如果我创建一个ArrayList<Integer> Room并运行:

Room.add(doc.get("Room", Integer.class))我得到java.lang.ClassCastException: Cannot cast java.lang.String to java.lang.Integer

仿佛“房间”有某种身份危机。

关于我可能遗失的任何提示?

Imagine a Document, named doc, that looks something like this:

"_id" : ObjectId("56896bbf713dffe8799e0970"), "Section Name" : "BUS-110-01", "Title" : "Business & Entrep. Mindset",, "Building" : "CCM", "Room" : 442, 443, "Days" : "T, TH", "Start Time" : "12:30 PM", "End time" : "1:45 PM",

When I run String myRoom = doc.getString("Room") I get an exception. I tried doc.getInteger("Room") and doc.getDouble("Room") and had no success, not that I expected much.

If I create an ArrayList<String> Room and run:

Room.add(doc.get("Room", String.class)) I get java.lang.ClassCastException: Cannot cast java.lang.Integer to java.lang.String

Ironically if I create an ArrayList<Integer> Room and run:

Room.add(doc.get("Room", Integer.class)) I get java.lang.ClassCastException: Cannot cast java.lang.String to java.lang.Integer

As if "Room" has some sort of identity crisis.

Any hints on what I might be missing?

最满意答案

应该更进一步。 ArrayList<Object> myList和myList.add(doc.get("Room", Object.class))解决了这个问题。

Should of gone one step furhter. ArrayList<Object> myList and myList.add(doc.get("Room", Object.class)) solved the issue.

更多推荐