Revision 47258
Added by Claudio Atzori almost 7 years ago
DnetLoggerMongoDao.java | ||
---|---|---|
10 | 10 |
import com.google.common.collect.Sets; |
11 | 11 |
import com.mongodb.BasicDBObject; |
12 | 12 |
import com.mongodb.BasicDBObjectBuilder; |
13 |
import com.mongodb.DBObject; |
|
14 | 13 |
import com.mongodb.client.MongoCollection; |
15 | 14 |
import com.mongodb.client.MongoCursor; |
16 | 15 |
import com.mongodb.client.MongoDatabase; |
... | ... | |
77 | 76 |
@Override |
78 | 77 |
public Map<String, String> findOne(final String collection, final String key, final String value) { |
79 | 78 |
final MongoCollection coll = db.getCollection(collection); |
80 |
final DBObject obj = (DBObject) coll.find(Filters.eq(key, value), DBObject.class).first();
|
|
79 |
final Document doc = (Document) coll.find(Filters.eq(key, value), Document.class).first();
|
|
81 | 80 |
//final DBObject obj = coll.find(getBasicQuery(key, value)).as(BasicDBObject.class); |
82 | 81 |
|
83 |
return dbObject2Map(obj);
|
|
82 |
return dbObject2Map(doc);
|
|
84 | 83 |
} |
85 | 84 |
|
86 | 85 |
@Override |
... | ... | |
151 | 150 |
return dateFilter; |
152 | 151 |
} |
153 | 152 |
|
154 |
private Iterator<Map<String, String>> iter(final MongoCursor<BasicDBObject> cursor) {
|
|
153 |
private Iterator<Map<String, String>> iter(final MongoCursor<Document> cursor) {
|
|
155 | 154 |
return new Iterator<Map<String, String>>() { |
156 | 155 |
|
157 | 156 |
@Override |
... | ... | |
171 | 170 |
}; |
172 | 171 |
} |
173 | 172 |
|
174 |
private Map<String, String> dbObject2Map(final DBObject obj) {
|
|
173 |
private Map<String, String> dbObject2Map(final Document doc) {
|
|
175 | 174 |
final Map<String, String> res = Maps.newHashMap(); |
176 |
if (obj != null) {
|
|
177 |
for (String k : obj.keySet()) {
|
|
178 |
res.put(k, "" + obj.get(k));
|
|
175 |
if (doc != null) {
|
|
176 |
for (String k : doc.keySet()) {
|
|
177 |
res.put(k, "" + doc.get(k));
|
|
179 | 178 |
} |
180 | 179 |
} |
181 | 180 |
return res; |
Also available in: Unified diff
save org.bson.Document instead of com.mongodb.DBObject