我想从 mongoDB 中获取数组元素并显示它,这是我的示例代码。
String[] previliges = new String[20];
String g_name = (String)jComboBox2.getSelectedItem();
DBCursor f;
BasicDBObject query = new BasicDBObject("group_name", g_name);
connection.MongoConnection con = new MongoConnection();
con.createConnection();
con.selectDB("test", "user_group");
f = con.coll.find(query);
previliges = (String[])f.next().get("privileges");
System.out.println(previliges.length);
它给了我一个例外 -> com.mongodb.BasicDBList 不能转换为 [Ljava.lang.String;
我来自 mongodb 集合的示例文档:
{
"_id" : ObjectId("51c7ebd9e4b096449a530024"),
"group_name" : "assss",
"privileges" : [
"View Log History",
"Communication"
]
}