Giter Club home page Giter Club logo

gmongo's People

Contributors

bdwheeler avatar bluesliverx avatar graemerocher avatar poiati avatar stefankendall2 avatar xsautejeau avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gmongo's Issues

Feature Requests

Hello Paulo,

I have been looking at your documentation on Github and on your site. I can't seem to find three features, pagination, sorting and find by id.

I have been able to get pagination to work by following the Java Driver syntax. However, I have not been able to get find by id to work. I tried db.collection.findOne(_id: id) but this does not return any thing. In addition, I tried to use the Java syntax db.collection.findOne( "_id", new ObjectId(id)) but that didn't work either.

Would it be possible to inject "findById" to the collection object?

Also, would it be possible to have a simpler api for paginating and sorting? I don't mind trying to hack something out and submit a patch. I was thinking of something like this db.collection.find([skip:0, limit:10, sort: "asc", orderBy: "lastName"]).

Thoughts?

MongoClient instead of Mongo

Need for use MongoClient instead of Mongo class because of replicaset connection properties, such read preferences.

Update by using "_id"

Hi,

I wanted to update something by id with gmongo. I have tried:
db.song.update([_id: "511048380364c13f5505c036"], [$set:[title: "GGGGGG"]])

It works when using another field as the key for updating, for example "title". What am I missing?
Thx /Lasse

Add support for java.util.Collections$SingletonList

An UnsupportedOperationException is thrown when using a SingletonList in an '$in' query when using the Grails Mongo Gorm plugin. Grails has this odd behavior where you get a SingletonList when converting an http parameter to a list (params.list('userIds')) on a one item parameter. In the cases where you have multiple items in the parameter you get an ArrayList, which works fine with gmongo. The work around is to use a mutable list or cast the value to a string array.

Here is an example of a Mongo Gorm call that would fail if the collection is a SingletonList
User.collection.find([_id: ['$in': singletonListOfIds]])

java.lang.UnsupportedOperationException
    at java.util.AbstractList.set(AbstractList.java:132)
    at com.gmongo.internal.Patcher$__converAllCharSeqToString_closure2_closure4.doCall(Patcher.groovy:89)
    at com.gmongo.internal.Patcher$__converAllCharSeqToString_closure2.doCall(Patcher.groovy:87)
    at com.gmongo.internal.Patcher._converAllCharSeqToString(Patcher.groovy:84)
    at com.gmongo.internal.Patcher$__converAllCharSeqToString_closure2.doCall(Patcher.groovy:102)
    at com.gmongo.internal.Patcher._converAllCharSeqToString(Patcher.groovy:84)
    at com.gmongo.internal.Patcher$__converAllCharSeqToString_closure2_closure4.doCall(Patcher.groovy:93)
    at com.gmongo.internal.Patcher$__converAllCharSeqToString_closure2.doCall(Patcher.groovy:87)
    at com.gmongo.internal.Patcher._converAllCharSeqToString(Patcher.groovy:84)
    at com.gmongo.internal.Patcher$__converAllCharSeqToString_closure2.doCall(Patcher.groovy:102)
    at com.gmongo.internal.Patcher._converAllCharSeqToString(Patcher.groovy:84)
    at com.gmongo.internal.Patcher._convert(Patcher.groovy:73)
    at com.gmongo.internal.Patcher._convert(Patcher.groovy:69)
    at com.gmongo.internal.Patcher$__patchInternal_closure1.doCall(Patcher.groovy:32)

add support for @Transient properties

It's desirable for domain classes to have synthetic, calculated properties. Ideally these synthetic properties will not be persisted to mongodb.

class Person {
def firstName
def lastName

@transient
def getFullName {
"$firstName $lastName"
}
}

Without support for @transient a fullName field is persisted to MongodB.

@transient would also allow read-only properties and support for @lazy.

GMongo enhancements fail when using invokeDynamic

When I try to compile my groovy module with Maven using Java 8 and the new gmaven plugin with invokedynamic, my tests fails because GMongo cannot convert maps and list containing teh requests to DbObject.

Thus I am forced to disable invokeDynamic

        <plugin>
            <groupId>org.codehaus.gmavenplus</groupId>
            <artifactId>gmavenplus-plugin</artifactId>
            <configuration>
                <invokeDynamic>false</invokeDynamic>
            </configuration>
        </plugin>

If I enable it, I have the following error:

Caused by: java.lang.ClassCastException: java.util.HashMap cannot be cast to com.mongodb.DBObject
        at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:219)
        at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:204)
        at com.mongodb.DBCollection.insert(DBCollection.java:148)
        at com.mongodb.DBCollection.insert(DBCollection.java:133)
        at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterf

I am using the Groovy 2.2.1 indy jar.

NPE when casting Map to BasicDBObject in find

When performing a find using Grails integration with mongo DB plugin, we are converting a map to a basic DB object using code similar to:

DomainClass.collection.find([name:"..."] as BasicDBObject)

This appears to be going through the Patcher.groovy file in gmongo, which is having a null exception when one or some of the property values are null in the map to be converted. This seems to trace to line 114 of Patcher, where the class of each "argument" is retrieved. Output from an integration test:

N/A
java.lang.NullPointerException
    at com.gmongo.internal.Patcher._types(Patcher.groovy:114)
    at com.gmongo.internal.Patcher._patchInternal_closure1(Patcher.groovy:33)
    at com.ace.mws.reports.Something.execute(Something.groovy:33)
    at com.ace.mws.reports.SomethingIntegrationSpec.Feature here(SomethingIntegrationSpec.groovy:22)

I'm not sure of the args property in the patcher, but can we use a null-safe groovy operator here to prevent problems? We are on grails 1.3.7 which means we use gmongo 0.9.1 as far as I can tell.

I'll submit a pull request, and let me know what you think. Thanks, Brian

gmongo 0.9 is compiled with Groovy 1.8 causing errors with Groovy 1.7

See http://hudson.grails.org/view/All/job/grails_data_mapping/lastCompletedBuild/testReport/org.grails.datastore.gorm.mongo/OneToOneIntegritySpec/Test_persist_and_retrieve_one_to_one_with_inverse_key/

The error is:

java.lang.NoClassDefFoundError: org/codehaus/groovy/runtime/BytecodeInterface8
at com.gmongo.internal.Patcher._convert(Patcher.groovy:64)
at com.gmongo.internal.Patcher._patchInternal_closure1(Patcher.groovy:32)

If you compile with Groovy 1.7 then it should be able to run in both 1.7 and 1.8 but if you compile with 1.8 it won't run in Groovy 1.7.

Could gmongo be updated to compile with 1.7 please?

Latest version of MongoDB supported and possible GMongo replacement?

I apologise for asking what might seem like two silly questions but I can't find this information elsewhere.

Background:

I have recently inherited a Grails 2 application that I'm upgrading to Grails 5. It has a LOT of GMongo-specific code. I can still use GMongo in Grails 5 as we are still targeting a legacy MongoDB 3.4.2 database.

However, I am also being asked to add PowerBI support to MongoDB, which requires an upgrade to at least MongoDB v4.0 (or MongoDB 5.0 if I want to use the Grails MongoDB plugin).

Question 1:

GMongo is a wrapper around the java-mongo-driver. What is the latest version of MongoDB GMongo 1.5 can support? Is it MongoDB v.3.x.x at most?.

Question 2:

This one is probably a long shot...but is there any replacement for GMongo in Grails 5/GORMfor MongoDB 5.0? The code base I have inherited has many thousands of lines of GMongo-specific code and if I want to upgrade MongoDB to support PowerBI, it means rewriting all of these using a recent Java Mongo driver.

It's a lot of work that I suspect I will have do do regardless, but I figure there's no harm in asking the GMongo author himself!

I'm also a little curious why this project was seemingly abandoned 8 years ago. Is it just not worth the time and effort any more given that Groovy and Grails aren't so popular?

Thanks in advance for any answers given. It's much appreciated.

cursor.count() result is incorrect

when I use gmongo in soapUI like this:
def cursor = db.contactInfo.find(broadcastId: "${broadcastId}")
result.count= cursor.count()

I always get count=10, but if I query from mongo shell directly, the result is 1, is it a bug or I am using it in wrong way?

Thanks!

suspect memory leak in gmongo 1.0

Hi,

I'm experiencing memory leaks since I started to use gmongo.

I read few mailing list post that you already identified and fixed a memory leak in v.0.7-0.8

The Eclipse Memory Analyzer identifies the following leak:

2,267 instances of "groovy.lang.ExpandoMetaClass", 
loaded by "org.apache.catalina.loader.WebappClassLoader @ 0xf5538ae8" 
occupy 61,576,696 (46.90%) bytes. 
These instances are referenced from one instance of "java.lang.Object[]", loaded by "<system class loader>"

Keywords
java.lang.Object[]
groovy.lang.ExpandoMetaClass
org.apache.catalina.loader.WebappClassLoader @ 0xf5538ae8

Looking at the heapdump those instances of ExpandoMetaClass is then holding MetaMethodIndex instances (several hundreds of thousands) for the same class
"DBApiLayer$MyCollection" and "DBCursor" with one set of methods of every method in the driver api.

My suspect is that the groovy delegates are continuously generated (multiple times) and retained by the class loader, so that you have multiple times the same delegates generated over and over for the same target Class.

Have you came across this problem?

regards
Bruno

Modifying an array from a document

Hello,

I'm testing gmongo and can't find an example of how to add an item to an array, for example my document is like: [name: 'XXX', cars:[]]
After I create that I need to add a car [brand:'xxx', model:'xxx'] to the person's cars array.

Can you give me any pointers of how to do that "the groovy way".

I've tried things like person.cars << [....] but doesn't seem to save anything.

Thanks a lot!

Write _id to map on save()

def x = [monkey: 23]
db.collection.save(x)
assertNotNull x._id

This will fail.
The reason, I assume, is because under the hood, you create a BasicDBObject under the hood from the Map,
then call save() using that BasicDBObject.

The problem is that the _id is lost.
I fixed it in my code by explicitly creating a BasicDBObject.

def x = new BasicDBObject(monkey: 23)
db.collection.save(x)
assertNotNull x._id

And that's fine.
It's just wierd, because it is different from the mongosh behavior for save() on a JSON object.

Would like GMongoClient to support all constructor signatures of MongoClient v 2.11.2

It would be nice if GMongoClient had constructors equivalent to the following:

// Creates a Mongo based on a list of replica set members or a list of mongos.
MongoClient(List<ServerAddress> seeds, List<MongoCredential> credentialsList)


// Creates a Mongo based on a list of replica set members or a list of mongos.
MongoClient(List<ServerAddress> seeds, List<MongoCredential> credentialsList, MongoClientOptions options)

Support for Groovy 1.7?

Is there any chance you could maintain a 1.7 build in maven for gmongo updates? I'm using grails 1.3.7, so I'm locked into 1.7.10. I'm investigating what it would take to move to Grails 2 right now, but it would be much simpler if there was a 1.7 build.

By moving to 1.8, all 1.3.7 Grails users are locked out. :/

GmongoClient should extend GMongo

In the java mongo driver MongoClient actually extends Mongo. So i think there can be some slight simplification here and addition of this chain of inheritence so it would be more consistent to use. We are running into a case where that was assumed and its failing as a result. We are working on a PR with a fix. just wanted to give you a heads up. Thanks on releasing 1.4 btw.

problem updating to gmongo-0.9.3

I use gmongo within a grails app and I tried bumping to v0.9.3 and ran into this error when trying to startup. I didn't see anything upgrade notes in the commit log. Is there something I need to update?

Thanks for a great library btw

2012-01-23 16:13:46,817 [Thread-8] ERROR context.GrailsContextLoader - Error executing bootstraps: groovy.lang.MissingMethodException: No signature of method: static com.gmongo.internal.MirrorObjectMutation.copyGeneratedId() is applicable for argument types: (com.brightcove.reporting.Domain, com.brightcove.reporting.Domain) values: [com.brightcove.reporting.Domain : null, ...]
Possible solutions: copyGeneratedId([Ljava.lang.Object;, [Ljava.lang.Object;), copyGeneratedId(java.util.List, java.util.List), copyGeneratedId(java.util.Map, java.util.Map)
org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: static com.gmongo.internal.MirrorObjectMutation.copyGeneratedId() is applicable for argument types: (com.brightcove.reporting.Domain, com.brightcove.reporting.Domain) values: [com.brightcove.reporting.Domain : null, ...]
Possible solutions: copyGeneratedId([Ljava.lang.Object;, [Ljava.lang.Object;), copyGeneratedId(java.util.List, java.util.List), copyGeneratedId(java.util.Map, java.util.Map)
at grails.util.Environment.evaluateEnvironmentSpecificBlock(Environment.java:290)
at grails.util.Environment.executeForEnvironment(Environment.java:283)
at grails.util.Environment.executeForCurrentEnvironment(Environment.java:259)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Caused by: groovy.lang.MissingMethodException: No signature of method: static com.gmongo.internal.MirrorObjectMutation.copyGeneratedId() is applicable for argument types: (com.brightcove.reporting.Domain, com.brightcove.reporting.Domain) values: [com.brightcove.reporting.Domain : null, ...]
Possible solutions: copyGeneratedId([Ljava.lang.Object;, [Ljava.lang.Object;), copyGeneratedId(java.util.List, java.util.List), copyGeneratedId(java.util.Map, java.util.Map)
at com.gmongo.internal.DBCollectionPatcher$__clinit__closure3.doCall(DBCollectionPatcher.groovy:41)
at com.gmongo.internal.Patcher._invoke(Patcher.groovy:50)
at com.gmongo.internal.Patcher$__patchInternal_closure1.doCall(Patcher.groovy:38)
at com.brightcove.reporting.DomainService.save(DomainService.groovy:48)
at com.brightcove.reporting.DomainService.demoData(DomainService.groovy:136)
at BootStrap$_closure1.doCall(BootStrap.groovy:14)
... 8 more

latest gmongo on maven

First off, great project!

Writing to check when the latest GMongo bits will make it to Maven.

Here's why:

I'm using gmongo within a grails project via the MongoDB plugin. I used your "clicks" group() example from the readme and changed it to an aggregate(), which gave me an error that a linkedHashMap couldn't be used. I checked the latest gmongo source and see that aggregate() is added to the patched methods list, which presumably would let me do this successfully:

db.clicks.aggregate(
[$group : [ _id : '$day' , clickCount : [$sum : '$total']] ]
)

Without the patch, I'm stuck with this:

def clicks = db.clicks.aggregate(
new BasicDBObject( [$group : [ _id : '$day' , clickCount : [$sum : '$total']] ] )
)

At this point I'm assuming that if I could point my project to the latest GMongo bits this would work fine.

Any estimate on how long it'll be before the latest code makes its way to maven?

Thanks!

Jndi connection

Not sure where else to ask this question.
Is it possible to connect gmongo to the mongo database via a jndi lookup?

cursor for aggregates >16MB?

In the Java driver you can specify using a cursor as an AggregationOption, but I'm not sure how to do this in gmongo. By default it doesn't use a cursor, and aggregation results are therefore limited to 16MB.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.