GithubHelp home page GithubHelp logo

Comments (2)

twillouer avatar twillouer commented on August 17, 2024

Hi,

perhaps you can use com.mongodb.DefaultDBDecoder do to this ?

I can integrate this in FongoRule if your test is good

from fongo.

Loki-Afro avatar Loki-Afro commented on August 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.