Can't get variable into a server.execute() function


#1

I have declared docId (for an chimp E2E-test) and I get the value in the console.

it('example', () => {
	const 	docId = browser.getAttribute('#target', 'data-id'),
	console.log(docId); // gives me a corret output.
	result = server.execute(() => { return Collection.find({ _id: docId }).fetch(); });
});

But then I get the error Uncaught Error: Error in server.executeReferenceError: docId is not defined.
To me it doesn’t make sense. What is my mistake?


#2

I get the same error with:

server.execute( function() {
   return Trips.find({});
});

Where Trips is a collection defined under /imports/api/

Any progress with troubleshooting?


#3

@j.myon - You may have already solved this, but, for the sake of posterity, here’s how it’s done:

const docId = browser.getAttribute('#target', 'data-id');
server.execute(function (docId) {
  return Collection.find({ _id: docId }).fetch();
}, docId);