cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Inserting a date from Neo4j into mongodb as date type

I am trying to insert a document into mongodb from Neo4j using apoc, and the document contains a date that I need to be received in mongodb as a date type. Here is an example of what I am sending:

CALL apoc.mongodb.insert('mongodb://localhost:27017','somedb','test',[{runAt: apoc.temporal.format(datetime(), 'ISO_DATE_TIME' )}])

I do receive the document on mongodb, the date is a string, which makes sense (because of apoc.temporal.format) , but I want it to be of type date in mongodb.

I tried almost everything, and I am stuck
Any help is appreciated.
Thanks

6 REPLIES 6

elwosto
Node Clone

Hi there,

Have you been able to find a solution for this?

I'm also facing date issues, but to perform a find with parameters within the query, like, "sent after this date". In MongoDB the documents do have the ISODate datatype.

I was able to use operators if I convert a stringified JSON to a map (with apoc), but still never been able to perform a date-related query:

call apoc.mongodb.find('localhost','convofier','recommender_ar',apoc.convert.fromJsonMap('{entry_created_at: {$gt: {$date: "2020-06-03T03:00:00"}}}'),{entry_created_at:1},null,true) yield value
return value

If I use an actual date time, like this:

call apoc.mongodb.find('localhost','convofier','recommender_ar',{entry_created_at: datetime("2020-06-03T03:00:00")},{entry_created_at:1},null,false) yield value
return value

I get

Failed to invoke procedure apoc.mongodb.find: Caused by: org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class java.time.ZonedDateTime.

Maybe @michael.hunger can lend us a helping hand here

Looking forward to solving this too

use localdatetime insteade of datetime. See below.

call apoc.mongodb.find('localhost','convofier','recommender_ar',{entry_created_at: localDatetime("2020-06-03T03:00:00")},{entry_created_at:1},null,false) yield value
return value

hope it helps

Thanks for the prompt reply!

I've tried and got the same error, but with localdatetime at the end:

What version of mongo drivers are you using?

Thanks!

Where you able to figure it out?

I am using neo4j version 4.0.0 and these plugins:
2X_8_8cd503805b631b4a17cd2035978e696f17ba05a7.png

check your bson version

elwosto
Node Clone

Hi there, thanks for the prompt reply

Unfortunately I haven't been able to run a query filtering by date, neither storing it. I ended up retrieving all records and filtering locally in Neo4j.

I'm using Neo4j 3.5, and MongoDB 3.6 drivers (though I do not have any of the Jackson ones you have )

I will play around with the drivers' versions and let you know.

Thanks again!