Comments (2)
Hi,
perhaps you can use com.mongodb.DefaultDBDecoder do to this ?
I can integrate this in FongoRule if your test is good
from fongo.
I messed around with org.bson.BSON (which uses DefaultDBDecoder
I guess) as well as com.mongodb.util.JSON but without success.
With org.bson.BSON
you get something like a DBObject
which can then be inserted in a collection, unfortunately it is getting inserted as one document instead of 18 which are in my bson dump.
When exporting json with some script (in mongo printJson(doc)
) it is not deserializeable with JSON.deserialize
due to ObjectID and dates I have in that document.
I came up with a more or less workaround:
Export Data from Live DB:
BasicDBObject query = new BasicDBObject();
query.put("destination", "OSL");
query.put("hotel", 140423);
DBCursor result = this.mongo.getDB("DB").getCollection("collectionName").find(query);
while (result.hasNext()) {
DBObject current = result.next();
Object id = current.get("_id");
FileUtils.write(new File("/myPath/" + id), JSON.serialize(current));
}
result.close();
Then importing into fongo like this:
File f = new File(ClassUtils.getDefaultClassLoader().getResource("pathInProject").toURI());
for (File f2 : f.listFiles()) {
DBObject dbObject = (DBObject) JSON.parse(new String(Files.readAllBytes(Paths.get(f2.toURI()))));
collection.insert(dbObject);
}
Maybe in the near future I will be able to import a bson dump itself but as I googled there were no options available in the Java Driver (you will find serveral similar requests)
Maybe this is also the reson why in tools like robomongo there is no Export/Import function.
from fongo.
Related Issues (20)
- Travis CI build fails
- Support for java mongodb driver 3.6.4+ HOT 12
- $size operator requires an array of 1 operand
- nm, sorry
- bulkWrite with a DeleteOneModel yields a modified count of 1
- FongoAsync and getMongoClient? HOT 1
- Feature request: support for IgnoreCase & IgnoreCaseAll SpringData methods
- When Fongo 2.2.* will be released? HOT 3
- Connecting to Fongo through a MongoDB client
- Marshalling error when using JodaModule with Jongo
- Fongo v2.2.0-RC2 incompatibility with mongodb driver v3.9.1 HOT 2
- $centerSphere doesn't seem to be supported
- java.lang.ClassNotFoundException: com.mongodb.Mongo + FongoRule + junit
- Aggregation $project, $unwind, $lookup returns EMPTY result, but works in a Java main()
- Everyone: when will we get a next release? - Fongo: a what?
- why does Fongo constructor takes a ServerVersion?
- Failed update embedded documents using $elemMatch
- Support for driver version 4.X HOT 6
- Support for spring auto configuration
- How can we get com.mongodb.client.MongoClient? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fongo.