How to update a MongoDB from Java with the current DB time? -


i want update mongo db java application current db time (not jvm's time).

if had shell, execute following command:

db.colletion.update({_id : 'doc'}, {$set : { last_update : isodate()}}, true, false); 

i'm not sure how translate java:

object lastupdate = ???; dbobject q = new basicdbobject("_id", "doc"); dbobject o = new basicdbobject("$set", new basicdbobject("last_update", lastupdate)); collection.update(q, o, true, false); 

i'm trying figure out should lastupdate object.

a new date instance not option, because represent jvm's time , not db's time.
thought using eval time db, cost query each update.
other ideas?

the way use eval. eval documentation:

if want use server’s interpreter, must run eval. otherwise, mongo shell’s javascript interpreter evaluates functions entered directly shell.

even command posted use client's time, not server time, because isodate constructor evaluated on client / shell.


Comments

Popular posts from this blog

rest - Spring boot: Request method 'PUT' not supported -

php - Magento - Deleted Base url key -

symfony - imagine_filter() not generating the correct url in LiipImagineBundle -