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

Mongodb client fails to find when asciidoctor has been required #1155

Open
viledub opened this issue Nov 24, 2020 · 2 comments
Open

Mongodb client fails to find when asciidoctor has been required #1155

viledub opened this issue Nov 24, 2020 · 2 comments

Comments

@viledub
Copy link

viledub commented Nov 24, 2020

Hi. I'm seeing a peculiar issue that I've traced to the initial exported function from asciidoctor (line 1 below). If you have a mongo database named "database" and a collection "collectionName" which is not empty, the code below should print out the contents of that collection. But when the asciidoctor require is present it prints an empty array.

I tried this with version 2.2.0 on node 14.15.1

const ad = require('asciidoctor')()
const { MongoClient } = require('mongodb');
const mongoSettings = '?authMechanism=SCRAM-SHA-256&authSource=admin';
const mongoUrl = "mongodb://user:password@localhost:27017"+mongoSettings;
const client = new MongoClient(mongoUrl);

async function main() {
	await client.connect()
	const th = await client.db('database').collection('collectionName').find().toArray()
	console.log(th);
}
main();
@ggrossetie
Copy link
Member

I can reproduce this issue.
For reference, Opal is modifying the prototype of base objects. I was able to find the root cause:

const Opal = require('asciidoctor-opal-runtime').Opal
Opal.add_stubs(['$id'])

https://github.com/opal/opal/blob/505fd5d7e899a6766472b302c079b4d383fd8216/opal/corelib/runtime.js#L1315-L1325

The MongoDB client must be using $id but since Opal redefines it, it has a side effect.

I will need to investigate a bit more to see if there's a workaround or a potential fix.

@ggrossetie ggrossetie added this to the v3.0.x milestone Dec 7, 2020
@ggrossetie
Copy link
Member

Upstream issue: opal/opal#2144

aepstein added a commit to aepstein/vumt that referenced this issue Jan 20, 2021
@ggrossetie ggrossetie removed this from the v3.0.x milestone Aug 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants