1

I'm working on a grails/mongodb project. I want to do a full text research on a mongodb database using:

db.test.runCommand( "text", { search : "my_texte" } )

The problem is that I didn't found how to do it in groovy (or using gmongo).

How do execute a "runCommand" from groovy ?

Thanks.

CC.
  • 2,736
  • 11
  • 53
  • 70

2 Answers2

2

I have found the Java version which works:

DBObject searchCmd = new BasicDBObject();
searchCmd.put("text", "test"); 
searchCmd.put("search", "mytexte"); 
CommandResult res = db.command( searchCmd )
CC.
  • 2,736
  • 11
  • 53
  • 70
  • Fair enough. It should. I would submit a bug to the maintainer though. The groovy syntax should be expected to work. Well picked up. – Neil Lunn Mar 26 '14 at 14:44
1

Since this is just a wrapper around the Java driver so most of the documentation is there.

Just translate into the "Groovy" form:

db.command( "text", [ search: "mytexte" ] )
Neil Lunn
  • 148,042
  • 36
  • 346
  • 317
  • Yes, I already tried but it does not work. I have the following error: "Caught: groovy.lang.MissingMethodException: No signature of method: com.mongodb.DBApiLayer$MyCollection.command() is applicable for argument types: (java.lang.String, java.util.LinkedHashMap)" – CC. Mar 26 '14 at 14:00
  • @CC. That is interesting indeed. Have you tried explicitly casting the "HashMap" as the second argument? This would seemingly be a bug if the general syntax is not accepted. – Neil Lunn Mar 26 '14 at 14:09
  • Still not working with HashMap but inside the doc I don't see the method taking a HashMap parameter for the command. – CC. Mar 26 '14 at 14:25
  • @CC. Sound like a bug. This should really be a straight through submit to the underlying method. Which surprises me in a way because this would be "heavily" implemented in the underlying Java code. But yet the signature here seems to be a problem. I may have more of a look into this myself. – Neil Lunn Mar 26 '14 at 14:30