google app engine and mongodb

2019-04-16 13:58发布

I'm using Java and MongoDB on google app engine but I cant find any reference on how to connect to MongoDB with Java.

I've tried with the following:

Maven:

    <dependency>
        <groupId>org.mongodb</groupId>
        <artifactId>mongo-java-driver</artifactId>
        <version>2.6.3</version>
    </dependency>

Java:

String serverName = ""; //provided external and internal ip addresses as well as name of mongoDB instance,
Mongo mongo = new Mongo(serverName); //com.addsapp.dao.MongoDB.initDB1(MongoDB.java:39)

And got the following result:

Uncaught exception from servlet
    java.lang.ExceptionInInitializerError
    at com.mongodb.Bytes.<clinit>(Bytes.java:215)
    at com.mongodb.MongoOptions.reset(MongoOptions.java:32)
    at com.mongodb.MongoOptions.<init>(MongoOptions.java:28)
    at com.mongodb.Mongo.<init>(Mongo.java:175)
    at com.mongodb.Mongo.<init>(Mongo.java:140)
    at com.addsapp.dao.MongoDB.initDB1(MongoDB.java:39)
    ...

Does anyone have a good Java reference on how to do this? Couldn't find anything on tzhe netz.

Thanks.

1条回答
相关推荐>>
2楼-- · 2019-04-16 14:44

You can't. You have to use the storage options given, like the datastore. You could connect via a web interface of course to an external instance, but I don't think that's what you are asking.

Take a look at compute http://googlecloudplatform.blogspot.co.uk/2014/06/running-mongodb-on-google-compute-engine.html

查看更多
登录 后发表回答