我的代码是
DBCollection collection = db.getCollection("volume");
DBCursor cursor = collection.find();
DBObject resultElement = cursor.next();
Map resultElementMap = resultElement.toMap();
System.out.println(resultElementMap);
结果是:
{_ id = 521b509d20954a0aff8d9b02,title = {“text”:“工作量 订单“,”x“: - 20.0},xAxis = {”title“:{”text“:”2012“}, “类别”:[“Jan”,“Feb”,“Mar”,“Apr”,“May”,“Jun”,“Jul” ,“Aug”,“Sep”,“Oct”,“Nov”,“Dec”]},yAxis = {“min”:1000.0, “max”:7000.0,“title”:{“text”:“Volume(K)”},“plotLines”:[{ “label”:{“text”:“Average”,“x”:25.0},“color”:“black”, “width”:2.0,“value”:30.0,“dashStyle”:“solid”}]},legend = { “backgroundColor”:“#FFFFFF”,“reverse”:true},series = [{“name” :“Volume”,“showInLegend”:false,“data”:[2909.0,3080.0, 4851.0,3087.0,2960.0,2911.0,1900.0,3066.0,3029.0,5207.0,3056.0,3057.0]}]}
我需要从结果中删除_id。我知道我需要和collection.find()一起玩,但请有人帮助我吗?我无法获得结果
答案 0 :(得分:6)
两个选项:
您可以从创建的地图中删除“_id”字段:
...
resultElementMap.remove("_id");
System.out.println(resultElementMap);
或者您可以要求查询结果不包含_id字段:
DBObject allQuery = new BasicDBObject();
DBObject removeIdProjection = new basicDBObject("_id", 0);
DBCollection collection = db.getCollection("volume");
DBCursor cursor = collection.find(allQuery, removeIdProjection);
DBObject resultElement = cursor.next();
Map resultElementMap = resultElement.toMap();
System.out.println(resultElementMap);
有关所有详细信息,请参阅projections上的文档。
答案 1 :(得分:0)
如果要迭代读取结果,则要考虑的另一种选择是执行以下操作:
react-native-permission