【问题标题】:Getting start with Jongo开始使用 Jongo
【发布时间】:2013-09-16 07:49:59
【问题描述】:

我正在尝试用 Jongo 运行一个“hello world”

我手动添加了 jar(不是使用 Maven)

这是我运行的代码:

public  class Friend {  
    @Id 
    private String myId;
}

public static void main(String[] args) {
MongoClient mongoClient = new MongoClient( "mydb.mongohq.com", 10014 );
        DB db = mongoClient.getDB( "db-name" );
        Jongo jongo = new Jongo(db);
        MongoCollection friends = jongo.getCollection("collection");
        Friend joe = new Friend();
        friends.save(joe);
}

我遇到了这个错误:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
    at java.lang.System.arraycopy(Native Method)
    at org.bson.io.PoolOutputBuffer.write(PoolOutputBuffer.java:74)
    at org.bson.LazyBSONObject.pipe(LazyBSONObject.java:451)
    at org.jongo.bson.BsonDBEncoder.writeObject(BsonDBEncoder.java:39)
    at com.mongodb.OutMessage.putObject(OutMessage.java:289)
    at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:239)
    at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:204)
    at com.mongodb.DBCollection.insert(DBCollection.java:148)
    at com.mongodb.DBCollection.insert(DBCollection.java:91)
    at com.mongodb.DBCollection.save(DBCollection.java:810)
    at org.jongo.Insert.save(Insert.java:55)
    at org.jongo.MongoCollection.save(MongoCollection.java:128)

【问题讨论】:

    标签: mongodb jackson bson jongo


    【解决方案1】:

    假设您已经添加了 jar 依赖项——Jackson 2.1、Bson4Jackson 2.1 和 Mongo Java Driver 2.9+——在我看来,您的 Friend 类没有私有构造函数。 The mapping section of the documentation详细解释一下。

    【讨论】:

      【解决方案2】:

      我的错误是使用 Jackson 2.2.1 而不是 2.1, 将其更改为 2.1 后,它工作得很好。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-08-07
        • 2013-01-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多