[英]Error: Invalid JSON object
我試圖運行此查詢,並繼續出現此錯誤:
install.packages(“mongolite”)
library(mongolite)
m <- mongo(db = "ionmom")
m6 <- m$aggregate('[{"$unwind":"$cdr"}, {$lookup:{from: "inventory", localField: "_id", foreignField: "_id", as:"inventory"}},{$unwind: "$inventory"}, {"$project":{ "$project": {"cdr.duration": 1, "inventory.wearables.type":1, "inventory.wearables.status":1, "inventory.wearables.battery":1 }}}]')
# Error: Invalid JSON object: [{"$unwind":"$cdr"}, {$lookup:{from: "inventory", localField: "_id", foreignField: "_id", as:"inventory"}},{$unwind: "$inventory"}, {"$project":{ "$project": {"cdr.duration": 1, "inventory.wearables.type":1, "inventory.wearables.status":1, "inventory.wearables.battery":1 }}}]
mongolite
在mongolite
使用jsonlite
進行JSON解析。 如果通過jsonlite::fromJSON()
查詢,則會看到問題
js <- '[{"$unwind":"$cdr"}, {$lookup:{from: "inventory", localField: "_id", foreignField: "_id", as:"inventory"}},{$unwind: "$inventory"}, {"$project":{ "$project": {"cdr.duration": 1, "inventory.wearables.type":1, "inventory.wearables.status":1, "inventory.wearables.battery":1 }}}]'
jsonlite::fromJSON(js)
# Error: lexical error: invalid char in json text.
# [{"$unwind":"$cdr"}, {$lookup:{from: "inventory", loc
# (right here) ------^
這是在告訴您JSON結構無效,因為它期望每個字符串都用引號" "
js <- '[{"$unwind":"$cdr"}, {"$lookup":{"from": "inventory", "localField": "_id", "foreignField": "_id", "as":"inventory"}},{"$unwind": "$inventory"}, {"$project":{ "$project": {"cdr.duration": 1, "inventory.wearables.type":1, "inventory.wearables.status":1, "inventory.wearables.battery":1 }}}]'
m$aggregate(js)
## I don't have your data ...
# Imported 0 records. Simplifying into dataframe...
# data frame with 0 columns and 0 rows
嘗試添加:
js <- '[{"$unwind":"$cdr"}, {"$lookup":{"from": "inventory", localField:}]'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.