我有下面的代碼在Groovy中插入一個文檔,但我不斷收到在Grails應用程序無法使用gmongo
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), inse (com.mongodb.WriteConcern,[Lcom.mongodb.DBObject;), insert(java.util.List,com.mongodb.WriteConcern)
此代碼取自gmongo的示例。任何想法爲什麼我得到一個錯誤?
UPDATE
我得到的Grails應用程序下面的錯誤嘗試@ dmahapatro的做法後:
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)
你特別指的是哪個例子?什麼是'getDocumentCollection()'?闡述。 – dmahapatro
聚合。 getDocumentCollection擴展爲mongo.getDB(「documents」)。getCollection(「zipcodes」) – allthenutsandbolts
1.爲什麼當你有[MongoDB for Grails插件](http://grails.org/plugin/mongodb)時顯式使用GMongo驅動程序? ? 2.顯示完整的代碼(類似於我的回答),在Grails應用程序中使用GMongo。 3.刪除爲堆棧跟蹤添加的額外答案。我已經添加了相同的主要問題。 – dmahapatro