我有以下代码可以在 groovy 中插入文档,但我在 grails 应用程序中不断收到此错误
def zipcode = getDocumentCollection()
zipcode.insert(["city": "ACMAR", "loc": [-86.51557F, 33.584132F], "pop": 6055, "state": "AL", "_id": "35004"])
没有方法签名:com.mongodb.DBApiLayer$MyCollection.insert() 适用于参数类型:(java.util.LinkedHashMap) 值:[[city:ACMAR, loc:[-86.51557, 33.584133], ...] ] 可能的解决方案:insert([Lcom.mongodb.DBObject;), insert(java.util.List), insert([Lcom.mongodb.DBObject;, com.mongodb.WriteConcern), insert(com.mongodb.DBObject, com .mongodb.WriteConcern),插入(com.mongodb.WriteConcern,[Lcom.mongodb.DBObject;),插入(java.util.List,com.mongodb.WriteConcern)
此代码取自 gmongo 的示例。任何想法为什么我会出错?
更新
在尝试@dmahapatro 的方法后,我在 Grails 应用程序中收到以下错误:
2013-06-06 09:54:21,493 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error initializing the application: Error creating bean with name 'org.springframework.data.mongodb.monitor.OperationCounters#0': Unsatisfied dependency expressed through constructor argument with index 0 of type [com.mongodb.Mongo]: Could not convert constructor argument value of type [com.gmongo.GMongo] to required type [com.mongodb.Mongo]: Failed to convert value of type 'com.gmongo.GMongo' to required type 'com.mongodb.Mongo'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.gmongo.GMongo] to required type [com.mongodb.Mongo]: no matching editors or conversion strategy found
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.data.mongodb.monitor.OperationCounters#0': Unsatisfied dependency expressed
through constructor argument with index 0 of type [com.mongodb.Mongo]: Could not convert constructor argument value of type [com.gmongo.GMongo] to required type [com.mongodb.Mongo]: Failed to
convert value of type 'com.gmongo.GMongo' to required type 'com.mongodb.Mongo'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.gmongo.GMongo] to required type [com.mongodb.Mongo]: no matching editors or conversion strategy found
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)