--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
thanks Geoff,
this is what I'm doing now, however the point is to store date fields in mongodb itself as isodate object and not as string. i need to compare dates in different timezones while running queries directly vs mongo.
--
You received this message because you are subscribed to a topic in the Google Groups "vert.x" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vertx/eMzeufLeCZw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vertx+un...@googlegroups.com.
hey david,
actually i already tried to use $date but i got a bson format exception saying it's unhappy with an attempt to use a $ in a key name... it's interesting that this stuff works with groovy, i think I'll dig into this again.
thanks.
--
@Test
public void testDate() {
JsonObject config = new JsonObject();
config.putString("address", "test");
config.putBoolean("fake", true);
container.deployModule("io.vertx~mod-mongo-persistor~2.1.0", config, new AsyncResultHandler<String>() {
@Override
public void handle(AsyncResult<String> asyncResult) {
if (asyncResult.failed()) {
container.logger().error(asyncResult.cause());
} else {
assertTrue(asyncResult.succeeded());
assertNotNull("deploymentID should not be null", asyncResult.result());
JsonObject dateField = new JsonObject();
dateField.putNumber("$date", new java.util.Date().getTime());
JsonObject document = new JsonObject();
document.putElement("createdOn", dateField);
JsonObject saveEvent = new JsonObject();
saveEvent.putString("action", "save");
saveEvent.putString("collection", "test");
saveEvent.putElement("document", document);
vertx.eventBus().send("test", saveEvent, (Handler<Message>) save_reply -> {
System.out.println(save_reply.body());
JsonObject mongoReply = (JsonObject)save_reply.body();
assertEquals("ok", mongoReply.getString("status"));
testComplete();
});
}
}
});
}
def eb = vertx.eventBus
String id = new org.bson.types.ObjectId().toHexString()
EventSequence sequence = new EventSequence()
sequence.activity {
container.deployModule("io.vertx~mod-mongo-persistor~2.1.0", [address: 'test', fake: true]) { result ->
if (result.succeeded) {
println "io.vertx~mod-mongo-persistor~2.1.0 has been deployed, deployment ID is ${result.result}"
sequence.next()
}
else {
println "io.vertx~mod-mongo-persistor~2.1.0 deployment failed ${result.cause().printStackTrace()}"
assertTrue(false)
sequence.stop()
}
}
}.activity {
Map document = [
_id: ['$oid': id],
create_date: ['$date': new Date().getTime()]
]
Map event = [
action: 'save',
collection: 'test',
document: document
]
eb.send("test", event) { response ->
assertEquals("ok", response.body.status)
sequence.next()
}
}.activity {
Map event = [
action: 'findone',
collection: 'test',
matcher: [_id: ['$oid': id]]
]
eb.send("test", event) { response ->
println response.body
//[result:[_id:[$oid:551fef1ed4c61493bd68c605], create_date:[$date:2015-04-04T14:03:10.400Z]], status:ok]
assertEquals("ok", response.body.status)
assertNotNull(response.body.result.create_date.'$date')
testComplete()
}
}.execute()
hey david, i see you took this challenge seriously :)
i use v3's vertx-mongo-ext and not v2's module, and also converting date to long isn't good enough since it kills the time zone.
as i said, i tried $date with a formatted string, but i got an exception. tomorrow I'll take another look to see where exactly it is thrown from.
thanks anyway!
Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.
Ok. You made me use Java for the first time in years. :-) Now I remember why I prefer Groovy.
Anyway this test seems to work:
@Test
public void testDate() {
JsonObject config = new JsonObject();
config.putString("address", "test");
config.putBoolean("fake", true);
container.deployModule("io.vertx~mod-mongo-persistor~2.1.0", config, new AsyncResultHandler<String>() {
@Override
public void handle(AsyncResult<String> asyncResult) {
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.