Members
-
<static> exports.getAllService
-
Description
Database query to fetch all documents of a collection.Parameters
Name Type Description model
mongoose.Model Mongoose model for the collection being queried. query
object MongoDB or Mongoose query to filter out documents. Returns
Examples
const { getAllService } = require("emfrest/services")
const arrayOfDocuments = await getAllService(model, query)
Details
-
<static> exports.createResourceService
-
Description
Database query to create a document.Parameters
Name Type Description model
mongoose.Model Mongoose model for the collection being queried. data
object Object with fields to be created in the specified document. Returns
Examples
const { createResourceService } = require("emfrest/services")
const document = await createResourceService(model, newDocumentData)
Details
-
<static> exports.getOneByIdService
-
Description
Database query to fetch a document by it's ObjectId.Parameters
Name Type Description model
mongoose.Model Mongoose model for the collection being queried. id
mongoose.ObjectId MongoDB ObjectId of the document to be fetched. Returns
Examples
const { getOneByIdService } = require("emfrest/services")
const document = await getOneByIdService(model, documentObjectId)
Details
-
<static> exports.updateOneByIdService
-
Description
Database query to update a document by it's ObjectId.Parameters
Name Type Description model
mongoose.Model Mongoose model for the collection being queried. id
mongoose.ObjectId MongoDB ObjectId of the document to be updated. newData
object Object with fields to be updated in the specified document. Returns
Examples
const { updateOneByIdService } = require("emfrest/services")
const document = await updateOneByIdService(model, documentObjectId, newDocumentData)
Details
-
<static> exports.deleteByIdService
-
Description
Database query to delete a document by it's ObjectId.Parameters
Name Type Description model
mongoose.Model Mongoose model for the collection being queried. id
mongoose.ObjectId MongoDB ObjectId of the document to be deleted. Returns
Examples
const { deleteByIdService } = require("emfrest/services")
const document = await deleteByIdService(model, documentObjectId)
Details