MongoDB query returns “Error: Invalid JSON object” on valid query

MongoDB query returns “Error: Invalid JSON object” on valid query

I have probably mucked up the syntax for the JSON query, but cannot for the life of me see where. Trying to create data.frame overviewData grouped on four values with an extra COUNT-feature.

Issue

I have probably mucked up the syntax for the JSON query, but cannot for the life of me see where. Trying to create data.frame overviewData grouped on four values with an extra COUNT-feature.

Code

overviewData <- M_CONNECTION$aggregate('[
        { 
            "$group" : {
                "_id" : {
                    "Hotel_Name" : "$Hotel_Name", 
                    "lat" : "$lat", 
                    "lng" : "$lng", 
                    "Average_Score" : "$Average_Score"
                }, 
                "COUNT(Hotel_Name)" : {
                    "$sum" : NumberInt(1)
                }
            }
        }, 
        { 
            "$project" : {
                "Hotel_Name" : "$_id.Hotel_Name", 
                "lat" : "$_id.lat", 
                "lng" : "$_id.lng", 
                "Average_Score" : "$_id.Average_Score", 
                "COUNT(Hotel_Name)" : "$COUNT(Hotel_Name)", 
                "_id" : NumberInt(0)
            }
        }
    ]',
options = '{"allowDiskUse" : true}'
)

I have quotes around all of my queries, as well as around the options. Still getting an "Invalid JSON object"-error message.

r json mongodb

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

MongoDB Database and java applications

Enroll for free demo to acquire the best knowledge on the schema-less database from live industry experts through MongoDB training

Which is the Best MongoDB GUI?

Our MongoDB Online Training provide you to learn about MongoDB strategies with realty. Our MongoDB Online Training also includes live sessions, live Projects, and much

Improve the MongoDB Aggregation Framework

Our MongoDB Online Training provide you to learn about MongoDB strategies with realty. Our MongoDB Online Training also includes live sessions, live Projects, and much

MongoDB – Database, Collection, and Document

Our MongoDB Online Training provide you to learn about MongoDB strategies with realty. Our MongoDB Online Training also includes live sessions, live Projects, and much

MongoDB brings database product range under one cloudy roof

Enroll for free demo to acquire the best knowledge on the schema-less database from live industry experts through MongoDB training