Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unnecessary boxing of objects making mongolite queries invalid #192

Open
nimame opened this issue Jun 25, 2017 · 1 comment
Open

Unnecessary boxing of objects making mongolite queries invalid #192

nimame opened this issue Jun 25, 2017 · 1 comment

Comments

@nimame
Copy link

nimame commented Jun 25, 2017

@jeroen suggested the following approach to build a mongolite query using jsonlite here:

query <- list(TIMESTAMP = list("$gte" =  as.POSIXct("2015-01-01")))
str <- jsonlite::toJSON(query, auto_unbox=TRUE, POSIXt = "mongo")

However, I get the follwing for str: {"TIMESTAMP":{"$gte":[{"$date":1420070400000}]}} (using jsonlite 1.5 on R 3.4.0) and the brackets around the "$date" object make the query invalid. I don't see a way of getting rid of them using jsonlite::toJSON. Is this a bug?

@yutannihilation
Copy link

fromJSON() also seems weird when there's only one $date object (though this is a rare case.)

library(jsonlite)

fromJSON('{"a": 1}')
#> $a
#> [1] 1
fromJSON('{"a": {"$date": 1549446556000}}')
#> [1] "2019-02-06 18:49:16 JST"
fromJSON('{"a": {"$date": 1549446556000}, "b": 2}')
#> $a
#> [1] "2019-02-06 18:49:16 JST"
#> 
#> $b
#> [1] 2

Created on 2019-02-06 by the reprex package (v0.2.1.9000)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants