Tips for composing MongoDB aggregation queries with Kotlin/JS

I am attempting to integrate Kotlin JS with the MongoDB Browser SDK. In JavaScript, the SDK supports a function that looks like this:

const someData = db("database")
        .collection("stories")
        .aggregate(
                [
                    {
                        $lookup:
                            { from: "person",
                              localField: "person_id",
                              foreignField: "_id",
                              as: "people"
                            }
                    }
                ]
        )

This is my attempt to convert it into Kotlin:

val aggregate = mapOf(
        "\$lookup" to mapOf(
                "from" to "people",
                "localField" to "people_id",
                "foreignField" to "_id",
                "as" to "people"
        )
)
val someData = mongodb
    .db("database")
    .collection("stories")
    .aggregate(aggregate)

However, I encounter the following error message:

Uncaught RangeError: Maximum call stack size exceeded

Any suggestions on how to resolve this issue?

Answer №1

Kotlin/JS mapOf does not work with regular JavaScript key-value objects. Instead, you can utilize the json function in Kotlin.

import kotlin.js.json

val aggregate = arrayOf(
    json(
        "\$lookup" to json(
            "from" to "people",
            "localField" to "people_id",
            "foreignField" to "_id",
            "as" to "people"
        )
    )
)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Dealing with errors using Javascript and Node.js (then/catch)

Suppose I have the following pseudocode in my routes.js file: var pkg = require('random-package'); app.post('/aroute', function(req, res) { pkg.impl_func(data, function (err, result) { myFunction(entity).then(user=>{ ...

When `switch_collection` is called, Mongoengine documents are saved without any fields

After utilizing the switch_collection method, I have encountered a peculiar issue while saving documents. This issue can be replicated using the code snippet below: import mongoengine as me class ObjectA(me.Document): name = me.StringField() def ...

Is there a way to transform a regular timestamp into a BSON timestamp format?

I am currently utilizing the https://www.npmjs.com/package/mongodb package. Upon inserting my timestamp, mongodb converts it into BSON format (which is expected). The original timestamp value is 641912491, but in the database it appears as 1457904327000. ...

JavaScript Object Featuring a Default Function Along with Additional Functions

I'm currently working on developing a custom plugin, but I've hit a roadblock at the initial stage. My goal is to create an object that can accept a parameter as its default and also include other functions within it. Below is an example of what ...

Addressing the problem of refactoring in JavaScript when associating arguments with keys in MongoDB

I am facing a dilemma with two functions that are almost identical except for the value being set as indicated: function extracted_start(details, txt) { return FutureTasks.upsert({ number: details.number ...

Build a complete React application with full-stack development using the WAMP stack on your local machine

Is there a way to set up a local development environment with React on the front-end and a full-stack server like WAMP? The goal here is to: Utilize the default React Create App setup without ejecting scripts Make AJAX requests to PHP files that interac ...

Displaying image while processing substantial ajax data

I implemented code to toggle the display of a loading image on my web page while making ajax requests. $(document).ajaxStart(function(){ $("#please_wait").css("display","block"); }); $(document).ajaxComplete(function(){ $("#please_wait").css(" ...

A gojs swim lane diagram requires a date axis to provide accurate time representation

I am currently working on a web application that requires a vertical swim lane activity diagram with a customized date axis displayed alongside it. The nodes in the diagram should be positioned based on their date attribute, and users should have the abili ...

Exploring the Power of Oembed with Hulu (and delving into the World of JSON

If anyone has insight into this process, it would be greatly appreciated. Here's the situation: I am trying to retrieve the embed URL from a Hulu video URL (e.g. 'www.hulu.com/watch/154344') using Javascript (jQuery is fine). Just to clarif ...

Button in Bootstrap input group moves down when jQuery validation is activated

Check out my bootstrap styled form: <div class="form-group"> <label for="formEmail">User Email</label> <div class="input-group"> <select class="form-control" data-rule-emailRequired="true" ...

Reaching a Particular Element in an Array Using Assignment Destructuring

I'm delving into assignment destructuring in my MongoDB/Node backend to handle post-processing. I am seeking clarity on how this feature operates, especially when dealing with arrays of multiple elements and nested arrays. Can I specify the element I ...

What is the best way to paginate aggregated results in Mongoose?

In my project, I have a User model that is linked to two other associated models - Profile and WorkProfile. The Profile model contains basic information about the user like name, email, and home address, while the WorkProfile model stores details such as o ...

What could be causing my mongoose array to remain empty without any values being stored in it?

Issue at Hand While I have come across several similar problems on Stack Overflow about this particular issue, none of the solutions provided seemed to work for me. I am in the process of developing a basic Forum application with two routes - one for cre ...

The 'Image' component does not have a propType defined for the native prop 'RCTImageView.overlayColor' with a native type of 'number'

Greetings, I am encountering an issue while attempting to run my react native application on Android. The app has been functioning flawlessly on iOS for several months, but this is our first endeavor at utilizing it on Android. We are using react-native .1 ...

Creating a horizontal slideshow for multiple divs can be achieved through various methods,

I'm feeling a little lost when it comes to creating a slideshow similar to this image: (Symbian^3 music menu) https://i.sstatic.net/oK0F2.png Can anyone provide me with a straightforward code example or a helpful resource to achieve something simila ...

Issue with JavaScript Replace not replacing second '<' character

I am attempting to swap out the < and > symbols of HTML tags with &gt; & &lt; by utilizing JavaScript. This is the code I am using: var sval = val.replace('&', '&amp;'); sval = sval.replace("<", "&lt;") ...

organize an array or JSON based on a numeric value or object in JavaScript

I encountered an issue related to sorting in JSON data. I have a list that can be reordered and the new order needs to be saved so that when the user returns, they see the list in the same customized order. Please refer to the image below: https://i.sstati ...

The positioning of the menu icons varies

When it comes to displaying the search icon in the WordPress toggle bar, I use a custom JavaScript file. This setup is mainly focused on website design and menu functionality. Additionally, I have integrated a newsletter subscription plugin for managing su ...

"Selections provided in the Summernote drop-down list

We are currently utilizing the Summernote rich-text editor (within MVC core) and have a need to incorporate a drop-down menu with varied display text in the menu, alongside the actual placeholder text that will be inserted into the editor. While we have f ...

Error: The React Hook "useX" should not be invoked at the top level of the code

I am facing a challenge while attempting to transfer the exception handling logic from the component to my service class: Login.tsx: import { useSnackbar } from "notistack"; // ... const Login = () => { const { enqueueSnackbar } = useSnack ...