Java Mongoddb返回\u id在插入文档后

Java Mongoddb返回\u id在插入文档后,java,mongodb,Java,Mongodb,我使用Java在MongoDB中插入一个文档: BasicDBObject document = new BasicDBObject(); document.put("Atmospheric_Pressure", Atmospheric_Pressure); document.put("Humidity", Humidity); collection.insert(document); System.out.println(document); 插入工作,我

我使用Java在MongoDB中插入一个文档:

BasicDBObject document = new BasicDBObject();
    document.put("Atmospheric_Pressure", Atmospheric_Pressure);
    document.put("Humidity", Humidity);

    collection.insert(document);

    System.out.println(document);
插入工作,我检查到集合,它是好的。System.out给了我以下结果:

{ "Atmospheric_Pressure" : "3" , "Humidity" : "3" , "_id" : { "$oid" : "539d964070d2dfc425fc06a0"}}
我的问题是我怎么才能只拿到身份证?我只需要第三项的值


提前谢谢。

您可以通过调用
document.getObjectId(“\u id”)
来获取它

这将返回类型为的对象。如果您只想获得字符串值,可以对返回的对象ID调用
toString()