将集合转换为 json 时如何去掉 mongo ID
How to get rid of the mongo IDs when converting a collection to json
我正在使用 mongo java API 将集合转换为 json:
MongoCollection<Document> coll = db.getCollection("day_EURUSD");
FindIterable<Document> fi = coll.find();
System.out.println(fi.first().toJson());
但是结果仍然包含 nongoDB 'clutter':
{ "_id" : { "$oid" : "565d90808b821237efdc39cb" }, "currencyPairs" : [{ "a....
我怎样才能优雅地摆脱 _id 和 $oid 以便我回到 'normal' json?
谢谢
试试这个:
MongoCollection<Document> coll = db.getCollection("day_EURUSD");
FindIterable<Document> fi = coll.find();
fi.forEach(new Block<Document>() {
@Override
public void apply(final Document document) {
// Suppress the DB Id column of the query result.
document.remove("_id");
}
});
...
我正在使用 mongo java API 将集合转换为 json:
MongoCollection<Document> coll = db.getCollection("day_EURUSD");
FindIterable<Document> fi = coll.find();
System.out.println(fi.first().toJson());
但是结果仍然包含 nongoDB 'clutter':
{ "_id" : { "$oid" : "565d90808b821237efdc39cb" }, "currencyPairs" : [{ "a....
我怎样才能优雅地摆脱 _id 和 $oid 以便我回到 'normal' json?
谢谢
试试这个:
MongoCollection<Document> coll = db.getCollection("day_EURUSD");
FindIterable<Document> fi = coll.find();
fi.forEach(new Block<Document>() {
@Override
public void apply(final Document document) {
// Suppress the DB Id column of the query result.
document.remove("_id");
}
});
...