I’m using MongodB Stitch functions to find one document by title on the sample_mflix.movies collection:
exports = function(arg){
let collection = context.services.get("mongodb-atlas").db("sample_mflix").collection("movies");
let doc = collection.findOne({"title": arg});
return {doc};
};
When I run this in Node.js, I get {doc: null}. Here’s my Node.js code:
const {
Stitch,
AnonymousCredential
} = require('mongodb-stitch-server-sdk');
Stitch.initializeDefaultAppClient('mflix-dskle');
/*client.auth.loginWithCredential(new AnonymousCredential()).then(user => {
console.log(user);
client.close();
}).catch(err => {
console.log(err);
client.close();
});*/
const client = Stitch.defaultAppClient;
console.log("logging in anonymously");
client.auth.loginWithCredential(new AnonymousCredential()).then(user => {
console.log(`logged in anonymously as user ${user.id}`)
});
client.callFunction("getMovies", ["Adventures in Babysitting"]).then(result => {
console.log(result);
});
Is this an issue with authentication? I’m using application authentication.