MongoDB findAndModify() in vert.x 3 MongoClient

245 views
Skip to first unread message

Hitesh Aleriya

unread,
Jul 2, 2015, 7:37:16 AM7/2/15
to ve...@googlegroups.com
Hello All,

I am using vert.x 3.0.0 with MongoDB 3.0.4 for my application. I read the official document of vert.x MongoClient but I didn't find any method like,  findAndModify(). MongoDB support this method, I want to update the collection and get back the updated value. I am unable to do this thing in vert.x. Can anyone have any idea around it or any alternative to achieve this. Please help me guys.

Thanks and Regards,
Hitesh

Paulo Lopes

unread,
Jul 2, 2015, 9:52:21 AM7/2/15
to ve...@googlegroups.com
findAndModify is not implemented on mongo-client and the java mongo-driver-async 3.0.2 does not seem to have that functionality built-in, you might need to break your code in 2 parts:

1) find the documents
2) perform the update

From the driver it seems that there is a FindOneAndReplace/findOneAndRemove but the findAndModify seems to be more generic that these 2 methods...

xunitc xc

unread,
Jul 2, 2015, 10:38:03 AM7/2/15
to ve...@googlegroups.com
hi, I think you can use:
def query = [
findAndModify: "table",
update: [ '$inc': [ "id": 1L ] ],
new: true,
upsert: false
];
mongo.runCommand("findAndModify", query, { result ->

}
by Groovy.

在 2015年7月2日星期四 UTC+8下午7:37:16,Hitesh Aleriya写道:
Reply all
Reply to author
Forward
0 new messages