2010-12-12 3 views
1

Je n'arrive pas à me connecter à MongoDB depuis le script Groovy.Problème avec mongo-java-driver sur MacOSX

Env:

trnls-mbpro:test trnl$ sw_vers 
ProductName: Mac OS X 
ProductVersion: 10.6.5 
BuildVersion: 10H574 
trnls-mbpro:test trnl$ java -version 
java version "1.6.0_22" 
Java(TM) SE Runtime Environment (build 1.6.0_22-b04-307-10M3261) 
Java HotSpot(TM) 64-Bit Server VM (build 17.1-b03-307, mixed mode) 
trnls-mbpro:test trnl$ groovy -version 
Groovy Version: 1.7.5 JVM: 1.6.0_22 
trnls-mbpro:test trnl$ mongod -version 
db version v1.6.4, pdfile version 4.5 
Sun Dec 12 03:34:32 git version: 4f5c02f8d92ff213b71b88f5eb643b7f62b50abc 
trnls-mbpro:test trnl$ 
trnls-mbpro:env trnl$ mongod -noauth -vvv 

Script test.groovy:

Mongo m = new Mongo("localhost", 27107); 
DB db = m.getDB("test"); 

BasicDBObject info = new BasicDBObject(); 

info.put("x", 203); 
info.put("y", 102); 

DBCollection collection = db.getCollection('user'); 

collection.insert(info); 

Résultats:

trnls-mbpro:test trnl$ groovy -cp mongo-2.1.jar test.groovy 
Caught: com.mongodb.MongoException$Network: can't say something 
    at test.run(test.groovy:16) 
trnls-mbpro:test trnl$ groovy -cp mongo-2.2.jar test.groovy 
Dec 12, 2010 3:30:24 AM com.mongodb.DBTCPConnector$MyPort error 
SEVERE: MyPort.error called 
java.io.IOException: couldn't connect to [trnls-mbpro.local/192.168.1.3:27107] bc:java.net.ConnectException: Connection refused 
    at com.mongodb.DBPort._open(DBPort.java:172) 
    at com.mongodb.DBPort.go(DBPort.java:79) 
    at com.mongodb.DBPort.say(DBPort.java:60) 
    at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:151) 
    at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:154) 
    at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:110) 
    at com.mongodb.DBCollection.insert(DBCollection.java:73) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSite.invoke(PojoMetaMethodSite.java:188) 
    at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52) 
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40) 
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) 
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124) 
    at test.run(test.groovy:16) 
    at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:264) 
    at groovy.lang.GroovyShell.run(GroovyShell.java:227) 
    at groovy.lang.GroovyShell.run(GroovyShell.java:157) 
    at groovy.ui.GroovyMain.processOnce(GroovyMain.java:496) 
    at groovy.ui.GroovyMain.run(GroovyMain.java:311) 
    at groovy.ui.GroovyMain.process(GroovyMain.java:297) 
    at groovy.ui.GroovyMain.processArgs(GroovyMain.java:112) 
    at groovy.ui.GroovyMain.main(GroovyMain.java:93) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108) 
    at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130) 
Caught: com.mongodb.MongoException$Network: can't say something 
    at test.run(test.groovy:16) 
trnls-mbpro:test trnl$ groovy -cp mongo-2.3.jar test.groovy 
Caught: com.mongodb.MongoInternalException: DBPort.findOne failed 
    at test.run(test.groovy:6) 
trnls-mbpro:test trnl$ 

Toute aide est appreci até.

-vova

Répondre

2

Le port par défaut pour MongoDB est 27017. Dans la documentation 27107.

0

Je ne suis ni un utilisateur ni OSX Groovy, mais pour moi, il semble que votre localhost est résolu un peu drôle. Je pense que localhost devrait résoudre à 127.0.0.1 et non 198.168.1.3.

Est-ce que vous avez quelque chose d'étrange dans votre/etc/hosts qui cause cela?

+0

Merci. Mais j'ai vérifié/etc/hosts et tout est OK là. Aussi, je suis capable de se connecter à db avec un client GUI. – trnl

Questions connexes