DBCollection.insert NoSuchMethodError

105 views
Skip to first unread message

eeb

unread,
Feb 15, 2011, 4:03:19 PM2/15/11
to mongodb-user
I have a Java class that references the mongo-2.4 driver, and I use
this class to do a simple insert like this:

BasicDBObject parse = (BasicDBObject)
JSON.parse(new String(docIn.flatten()));
DBCollection collection = db.getCollection(collectionName);
collection.insert(parse);

I compile my new class and put both it and the driver on the classpath
of my server, which has a service that calls my new class. When the
call is made to my class I get the following error:

java.lang.NoSuchMethodError: com.mongodb.DBCollection.insert(Lcom/
mongodb/DBObject;)V
java.lang.NoSuchMethodError:
com.mongodb.DBCollection.insert(Lcom/mongod
b/DBObject;)V...

The only reference to this error that I can find online is here:
http://log4mongo.org/display/PUB/Log4mongo+for+Java

Since I am compiling with mongo-2.4.driver this shouldn't be a binary
compatibility issue though.

Any help you guys could give would be greatly appreciated.

eeb



sridhar

unread,
Feb 15, 2011, 4:26:51 PM2/15/11
to mongodb-user
what is your java version?

sridhar

unread,
Feb 15, 2011, 4:29:46 PM2/15/11
to mongodb-user
also what is your version of log4mongo?

sridhar

unread,
Feb 15, 2011, 5:24:48 PM2/15/11
to mongodb-user
Hi, you mention using a service that uses your class. Can you see if
one of the following fixes the issue
1) have you tried using your class from a simple command line app. If
so it might be a problem with the classloader of your service having a
problem with the varargs argument of the insert method
2) you can alternatively modify your insert to
collection.insert(Arrays.asList(parse))
Thanks

eeb

unread,
Feb 16, 2011, 10:37:19 AM2/16/11
to mongodb-user
Thanks for your reply sridhar!

I am using java 1.6.0_23. I am not using log4mongo. Sorry for the
confusion. I referenced the log4mongo page, because it is the only
Google result containing the same error.

I will try your other suggestions today.

Thanks again.

eeb

unread,
Feb 16, 2011, 11:43:11 AM2/16/11
to mongodb-user
I am sad to say this turned out to be a mistake on my part. I had
changed the jar name containing my class awhile back, and on this
particular server the old jar still existed on the classpath.

Thanks again for the help sridhar and sorry to have wasted your time.

sridhar

unread,
Feb 16, 2011, 12:59:18 PM2/16/11
to mongodb-user
no worries. Glad your issue got resolved
Reply all
Reply to author
Forward
0 new messages