data()
import { createBackendFunction, data } from "@magicjs.dev/backend";
import { ObjectId } from 'mongodb';
export default createBackendFunction(async function (id) {
try {
const itemCollection = data('mongoDbCollectionName');
// Pass the MongoDB collection name as an argument to the data function,
// allowing you to retrieve the corresponding data collection.
const itemsDetails = await itemCollection.findOne({
_id: new ObjectId(id)
});
return itemsDetails;
} catch (error) {
throw new Error(`Network error`);
}
});Last updated