我在 mongo 中有以下文档:
> { "_id": ObjectId("569afce4b932c542500143ec"),
> "date": "2016-1-17T2:31:0Z",
> "day": NumberInt(17),
> "model1": {
> "date": "2016-01-17T02:31+0000",
> "MondayModel": {
> "gtxdotdot": {
> "xdotdot": 0,
> "xdot": 0
> },
> "lsxdotdot": {
> "xdotdot": 0,
> "xdot": 0
> },
> "gtxdot": {
> "xdotdot": 0,
> "xdot": 0
> },
> "lsxdot": {
> "xdotdot": 0,
> "xdot": 0
> },
> "modeldotdot": {
> "mean": 0,
> "sdvar": 0
> },
> "modeldot": {
> "mean": 0,
> "sdvar": 0
> }
> }
> }
我希望既能找到这份文件,又希望只提取model1.MondayModel.gtxdotdot.xdotdot/xdot/mean/sdvar
...的值
我当前的代码使用以下代码:
MongoCursor<Document> back = collection.find(and(eq("topic",topic),eq("sp",sp))).limit(1).iterator();
if (back.hasNext())
{
Document doc = back.next();
Document tmpddc1 = (Document)doc.get("model1");
Document tmpddc2 = (Document)tmpddc1.get("MondayModel");
Document tmpddc3 = (Document)tmpddc2.get("gtxdotdot");
gtxdotdotXdotdot = tmpddc3.getDouble("xdotdot");
gtxdotdotXdot = tmpddc3.getDouble("xdot");
tmpddc3 = (Document)tmpddc2.get("lsxdotdot");
lsxdotdotXdotdot = tmpddc3.getDouble("xdotdot");
lsxdotdotXdot = tmpddc3.getDouble("xdot");
tmpddc3 = (Document)tmpddc2.get("gtxdot");
gtxdotXdotdot = tmpddc3.getDouble("xdotdot");
gtxdotXdot = tmpddc3.getDouble("xdot");
tmpddc3 = (Document)tmpddc2.get("lsxdot");
lsxdotXdotdot = tmpddc3.getDouble("xdotdot");
lsxdotXdot = tmpddc3.getDouble("xdot");
tmpddc3 = (Document)tmpddc2.get("modeldotdot");
modeldotdotXmean = tmpddc3.getDouble("mean");
modeldotdotXsdvar = tmpddc3.getDouble("sdvar");
tmpddc3 = (Document)tmpddc2.get("modeldot");
modeldotXmean = tmpddc3.getDouble("mean");
modeldotXsdvar = tmpddc3.getDouble("sdvar");
}
而不是运行思想他记录(如上)有没有办法使用点符号来获取值[model1.MondayModel.gtxdotdot.xdotdot]
?例如:
double value = doc.getDouble("model1.MondayModel.gtxdotdot.xdotdot");