Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6186841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:57:28+00:00 2026-05-24T01:57:28+00:00

I am trying to do a safe insert using GORM for Mongo’s low-level API.

  • 0

I am trying to do a safe insert using GORM for Mongo’s low-level API.

I have reproduced the problem in a clean Grails project like follows:

  1. Create a new Grails project
  2. Uninstall the Hibernate plugin
  3. Install the GORM for Mongo plugin
  4. Create a controller with the following action

    import com.mongodb.*
    
    class TestController {
    
        def mongo
    
        def index = {
    
            def database = mongo.getDB("ExampleDatabase")
            def collection = database.getCollection("ExampleCollection")
    
            def document = new BasicDBObject();
            document.put("key", "value")
    
            collection.insert(document, WriteConcern.SAFE)
    
            render ""
    
        }
    }
    
  5. When firing the action, the following exception is thrown:

    2011-07-27 12:53:03,161 [http-8080-1] ERROR errors.GrailsExceptionResolver  - Exception occurred when processing request: [GET] /WriteConcern.SAFE-test/test/index
    Stacktrace follows:
    groovy.lang.MissingPropertyException: No such property: value for class: com.mongodb.WriteConcern
        at com.gmongo.internal.Patcher$__converAllCharSeqToString_closure2.doCall(Patcher.groovy:81)
        at com.gmongo.internal.Patcher._converAllCharSeqToString(Patcher.groovy:80)
        at com.gmongo.internal.Patcher$_converAllCharSeqToString.callStatic(Unknown Source)
        at com.gmongo.internal.Patcher$_converAllCharSeqToString.callStatic(Unknown Source)
        at com.gmongo.internal.Patcher._convert(Patcher.groovy:69)
        at com.gmongo.internal.Patcher$_convert.callStatic(Unknown Source)
        at com.gmongo.internal.Patcher$__patchInternal_closure1.doCall(Patcher.groovy:31)
        at writeconcern.safe.test.TestController$_closure1.doCall(TestController.groovy:17)
        at writeconcern.safe.test.TestController$_closure1.doCall(TestController.groovy)
        at java.lang.Thread.run(Thread.java:680)
    
  6. If I change the action to use the Mongo Java API as follows:

    def index = {
    
        def database = new Mongo().getDB("ExampleDatabase")
        def collection = database.getCollection("ExampleCollection")
    
        def document = new BasicDBObject();
        document.put("key", "value")
    
        collection.insert(document, WriteConcern.SAFE)
    
        render ""
    
    }
    
  7. Now it works and the document is persisted to the Mongo database as expected.

My question is this: Is this a bug with the GMongo wrapper, or then how should safe writes be done using the low level API?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T01:57:29+00:00Added an answer on May 24, 2026 at 1:57 am

    This appears due to the GMongo library and how it patches the DBCollection object to handle passing of Map objects to the insert method and converts them. It assumes that all of the arguments of the insert method are Map objects and will then try to get the value property from the Map.Entry.

    Looking at the source of Patcher.groovy from GMongo library you’ll see the function _convert() that attempts to do this. It looks like a fork of the Github project with type check on the argument (either to see if it’s a WriteConcern or to check if it’s actually a Map before passing to the _converAllCharSeqToString) is necessary.

    EDIT:

    I created a pull request on Github for the appropriate code change, but as with all things Groovy, patching the class can also help. You can “patch” the WriteConcern class in your BootStrap.groovy to have a getValue method and that will allow you to pass the parameter in:

    def init = { servletContext ->
        com.mongodb.WriteConcern.metaClass.getValue  = { null }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application where I am trying to implement a safe file overwrite
I'm trying to write a thread-safe queue using pthreads in c++. My program works
I am using entity framework to insert details into the database where I have
I'm trying to do the safe thing, and have a program that needs to
I'm trying to use ThreadLocal to provide thread safety to pre-existing non-thread-safe classes, but
I am trying to put together a proof of concept of an XSS-safe string
Im trying to compile a simple class library project,its from Source Safe. However,when i
I'm trying to make a URL-safe version of a string. In my database I
I realize that what I am trying to do isn't safe. But I am
I am trying to write to different pieces of a large file using multiple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.