Hi everyone.
I’m using Atlas MongoDB. I have added a data source starting from a HTTP(S) URL pointing to a CSV file and I have create a collection inside a VirtualDatabase. Everything works well infact I’m able to query this collection both from Compass or with custom code from VS Code. Unfortunately I can’t read data from inside a linked function associated to an HTTP Endpoint. This is the source of my function:
exports = async function() {
const serviceName = ‘mongodb-atlas’;
const myDataLake = context.services.get(serviceName);
const myDB = myDataLake.db(‘VirtualDatabase0’);
return await myColl.find({first_name: “Lissie”});
}
Unfortunately the result is always an empty collection (the query is right - tested on VS Code).
Hoping someone can help me.
Is this missing myColl? When I tried to execute your lines of code but with reference to my own test data sources, I got back the following error:
{“message”:“‘myColl’ is not defined”,“name”:“ReferenceError”}
You have a link to the database VirtualDatabase0 but the query is being run without a collection specified.
I wrote something similar on my test environment function which had included a reference to an existing collection in the federated instance which returned an expected document:
Anyway, the result is always the same either with find() and findOne() method, with or without filters. This is my result obtained by using “Run” from the funciont edito window:
ran at 1688980963940
took 529.584588ms
result:
result (JavaScript):
EJSON.parse(‘’)
I noticed that you call your service name as ‘fdi’. In my case the service name is ‘mongdb-atlas’. While this linked datasource of my app has is pointing to the “cluster” instance, I created a new linked source that refers to the Federated Database Instance that, infact, is the environment where the external data source is linked.
By changing the service name everything worked.