wise-coders/mongodb-jdbc-driver

There are many functions that are not supported

Closed this issue · 8 comments

I use this driver connect operator mongodb,Connection by JDBC,but i find many functions not supported, just like aggregate、group、findOne etc, Is there any other way to solve it,Thanks!

Thank you for reporting this issue. Can you please add some code we can test ? I tried executing this below from DbSchema and for me it works fine. We would need a list of queries to check.

db.orders.insertOne( { _id: 1, item: { category: "cake", type: "chiffon" }, amount: 10 } );
db.orders.insertOne( { _id: 2, item: { category: "cookies", type: "chocolate chip" }, amount: 50 } );
db.orders.insertOne( { _id: 3, item: { category: "cookies", type: "chocolate chip" }, amount: 15 } );
db.orders.insertOne( { _id: 4, item: { category: "cake", type: "lemon" }, amount: 30 } );
db.orders.insertOne( { _id: 5, item: { category: "cake", type: "carrot" }, amount: 20 } );
db.orders.insertOne( { _id: 6, item: { category: "brownies", type: "blondie" }, amount: 10 } );

db.orders.find();

db.orders.aggregate([
   { $group: { _id: "$category", total: { $sum: "$amount" } } }
])

Thank you for you answer,I tested the situation,no question!

db.dogroup.insert({"_id": 1,"name": "N",course: "C","score": 5,gender: 0})
db.dogroup.insert({"_id": 2,"name": "N",course: "O","score": 4,gender: 0})
db.dogroup.insert({"_id": 3,"name": "A",course: "C","score": 5,gender: 1})
db.dogroup.insert({"_id": 4,"name": "A",course: "O","score": 6,gender: 1})
db.dogroup.insert({"_id": 5,"name": "A",course: "U","score": 8,gender: 1})
db.dogroup.insert({"_id": 6,"name": "A",course: "R","score": 8,gender: 1})
db.dogroup.insert({"_id": 7,"name": "A",course: "S","score": 7,gender: 1})
db.dogroup.insert({"_id": 8,"name": "M",course: "C","score": 4,gender: 0})
db.dogroup.insert({"_id": 9,"name": "M",course: "U","score": 7,gender: 0})
db.dogroup.insert({"_id": 10,"name": "E",course: "C","score": 7,gender: 1})

when I execute this code:
db.dogroup.aggregate({$group: {_id:"$course",count:{$sum: 1}}},{$match:{count:{$gt: 2}}});

ResultSet resultSet = statement.executeQuery("db.dogroup.aggregate({$group: {_id:"$course",count:{$sum: 1}}},{$match:{count:{$gt: 2}}})") ;

error msg :
java.sql.SQLException: TypeError: Can not invoke method [jdk.internal.dynalink.beans.OverloadedDynamicMethod\n AggregateIterable com.dbschema.wrappers.WrappedMongoCollection.aggregate(ClientSession,List,Class)\n AggregateIterable com.dbschema.wrappers.WrappedMongoCollection.aggregate(ClientSession,List)\n AggregateIterable com.dbschema.wrappers.WrappedMongoCollection.aggregate(List,Class)\n AggregateIterable com.dbschema.wrappers.WrappedMongoCollection.aggregate(List)\n] with the passed arguments; they do not match any of its method signatures. in at line number 1"

All execute i use ResultSet rs = statement.executeQuery( query );

db.dogroup.getIndexes()
Error msg: {
"data": {
"msg": java.sql.SQLException: TypeError: db.orders.getIndexes is not a function in ###eval ### at line number 1",
"success": false
},
"statu": 0
}

db.dogroup.findOne({"score":8})
Error msg:
{
"data": {
"msg": java.sql.SQLException: TypeError: db.orders.findOne is not a function in ###eval ### at line number 1",
"success": false
},
"statu": 0
}

db.dogroup.createIndex({score:1},{background:1}) OK

db.dogroup.dropIndex("score_1") OK

db.dogroup.getIndexSpecs()
{
"data": {
"msg": "java.sql.SQLException: TypeError: db.orders.getIndexSpecs is not a function in ###eval ###at line number 1",
"success": false
},
"statu": 0
}
Many error displays eval function, i search stackoverflow https://stackoverflow.com/questions/47093563/how-to-execute-mongodb-native-query-json-using-mongo-java-driver-only/61931474?noredirect=1#comment109538041_61931474

the eval function Deprecated since version 3.0. https://docs.mongodb.com/manual/reference/method/db.eval/
i use mongodb 4.0 cluster

Thank you for reporting this. Now this statement is fixed, new jars are deployed on DbSchema.com website. Please us know if you find any other statement which does not work, we will try to fix them faster.

Thank you for your answer, I will test, if I find other problems, I will submit!,Thank you for your support!

hello, I found new problems, insert below code ,when querying through
db.activity.aggregate(
{"$match":{
"createdAt": {'$gte':ISODate("2020-03-26T00:00:00Z"),'$lt':ISODate("2020-04-11T00:00:00Z")}
}},
{"$group": {
"_id": {
"createdAt":{"$subtract": [
{ "$subtract": [ "$createdAt", new Date("1970-01-01") ] },
{ "$mod": [
{ "$subtract": [ "$createdAt", new Date("1970-01-01") ] },
1000 * 60 * 60
]}
]},"shopId":"$shopId"
},
"count": {"$sum": 1}
}},
{"$project": {
"_id": 0,
"count": 1,
"shopId":'$_id.shopId',
'datetime': {'$add': [new Date(0), '$_id.createdAt']}
}},
{"$sort": {
'datetime': 1
}}
)

here insert sql:
db.activity.insert({"_id":"0003645026e511eaa4ec3622135d06d8","shopId":"baaacd90d36e11e9adb40a8baad32c5a","creatorId":"f1259450adf711e9a21376ce84e4d9c7","name":names20","thirdActivityUrl":"https://aliyx..xx/coupon/2525808722/edit?spm=a21y7.9633641.0.0.56f3104dEM7IMv\u0026couponType=0\u0026templateId=null","channel":"","channelName":"","type":"DISPOSABLE_COUPON","subType":"NORMAL","extensionField":{"pullMethod":"name","amount":"500"},"deleted":true,"productCount":1,"unknownProductCount":499,"productProperties":[{"_id":"couponUrl","name":"names","type":"TEXT","options":[],"encrypted":false,"validated":true,"errorMsg":[],"readOnly":false,"action":"","pageNum":1}],"skuProperties":[],"createdAt":{"$date":"2019-12-25T07:05:57.779Z"},"lastModifiedAt":{"$date":"2019-12-25T07:23:18.408Z"},"_class":".domain.Activity"})
db.activity.insert({"_id":"0003f5a0c4f211e9a5d64e7f2fc82e35","shopId":"a8f40b30a92911e9b5ad0242ac110002","creatorId":"500b46b0720511e9997c0242ac110002","name":"names","thirdActivityUrl":"https://tmc.sale..xx/page/campaign/signdetail.htm?signRecordId=106705809","channel":"","channelName":"","type":"PERSONALIZED_MATERIAL_EDIT","subType":"NORMAL","deleted":false,"productCount":0,"unknownProductCount":0,"productProperties":[],"skuProperties":[],"createdAt":{"$date":"2019-08-22T15:32:07.288Z"},"lastModifiedAt":{"$date":"2019-08-22T15:36:27.409Z"},"_class":".domain.Activity"})

db.activity.insert({'time':ISODate("2012-11-02 07:58:51")})
java.sql.SQLException: java.text.ParseException: Unparseable date: "2012-11-02 07:58:51"

Thank you for reporting this. We added more patterns to the ISODate. This is defined in our code as a function which tries to match different formats.
Currently configured formats: var formats = ["yyyy-MM-dd'T'HH:mm:ss'Z'", "yyyy-MM-dd'T'HH:mm.ss'Z'", "yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd' 'HH:mm:ss","yyyy-MM-dd'T'HH:mm:ssXXX"]

New driver is now uploaded on DbSchema website.
Please test this and let me know if is working fine.

We identified also more issues in the tests you provided:

  1. Sometimes you use "$date". I think you should escape the '$' ('$') or avoid it. I am not sure how MongoDb is using it, but JavaScript is considering it a variable.

  2. The statements you provided are pretty complex. If you still get errors please try to create more simple statements, so is easier to separate the issues.

thank you very much!! I will pay attention when use ‘$’ syntax。
I use mongodb more now, I found many problems when using it, most of them are not supported by the function, I will give you feedback after finishing, thank you again!!