If this is a discriminator model, baseModelName is the name of
the base model.
Collection the model uses.
Connection the model uses.
Registered discriminators for this model.
Event emitter that reports any errors that occurred. Useful for global error handling.
The name of the model
Schema the model uses.
Adds a $where clause to this query
Sends multiple insertOne, updateOne, updateMany, replaceOne,
deleteOne, and/or deleteMany operations to the MongoDB server in one
command. This is faster than sending multiple independent operations (e.g.
if you use create()) because with bulkWrite() there is only one round
trip to MongoDB.
Creates a count query: counts the number of documents that match filter.
Creates a countDocuments query: counts the number of documents that match filter.
Creates a new document or documents
Create the collection for this model. By default, if no indexes are specified, mongoose will not create the collection for the model until any documents are created. Use this method to create the collection explicitly.
Similar to ensureIndexes(), except for it uses the createIndex
function.
Deletes all of the documents that match conditions from the collection.
Behaves like remove(), but deletes all documents that match conditions
regardless of the single option.
Deletes the first document that matches conditions from the collection.
Behaves like remove(), but deletes at most one document regardless of the
single option.
Adds a discriminator type.
Creates a distinct query: returns the distinct values of the given field that match filter.
Sends createIndex commands to mongo for each index declared in the schema.
The createIndex commands are sent in series.
Creates a estimatedDocumentCount query: counts the number of documents in the collection.
Returns true if at least one document exists in the database that matches
the given filter, and false otherwise.
Fetch the records from MyFood API
The id of the greenhouse from the MyFood API
The maximum amount of records to keep (most recent first), -1 for all (default: -1)
The Measures from the fetched records
const greenhouseId = 91
const records = await Measure.fetchMyFoodRecords(greenhouseId)
Fetch the records from MyFood API, but only returns the measures that are not registered in the database
The id of the greenhouse from the MyFood API
The maximum amount of records to keep (most recent first), -1 for all (default: -1)
The filtered records
const greenhouseId = 91
const newRecords = await Measure.fetchUnregisteredRecords(greenhouseId)
// to get only the last entry for each sensor
const newRecords = await Measure.fetchUnregisteredRecords(greenhouseId, 6)
Filter all the given measures to keep only the ones the are not registered in the database
The measures to filter
The filtered measures
const records = await Measure.fetchMyFoodRecords(greenhouseId)
const newRecords = await Measure.filterUnregisteredRecords(records)
Creates a find query: gets a list of documents that match filter.
Finds a single document by its _id field. findById(id) is almost*
equivalent to findOne({ _id: id }). If you want to query by a document's
_id, use findById() instead of findOne().
Creates a findByIdAndDelete query, filtering by the given _id.
Creates a findByIdAndRemove query, filtering by the given _id.
Creates a findOneAndUpdate query, filtering by the given _id.
Finds one document.
Creates a findOneAndDelete query: atomically finds the given document, deletes it, and returns the document as it was before deletion.
Creates a findOneAndRemove query: atomically finds the given document and deletes it.
Creates a findOneAndReplace query: atomically finds the given document and replaces it with replacement.
Creates a findOneAndUpdate query: atomically find the first document that matches filter and apply update.
Get a sensor type by it's name
Sensor name
Sensor type
const sensorName = record.sensor
const sensor = Measure.getSensorByName(sensorName)
Shortcut for creating a new Document from existing raw data, pre-saved in the DB. The document returned has no paths marked as modified initially.
This function is responsible for building indexes,
unless autoIndex is turned off.
Mongoose calls this function automatically when a model is created using
mongoose.model() or
connection.model(), so you
don't need to call it.
Inserts one or more new documents as a single insertMany call to the MongoDB server.
Lists the indexes currently defined in MongoDB. This may or may not be
the same as the indexes defined in your schema depending on whether you
use the autoIndex option and if you
build indexes manually.
Executes a mapReduce command.
Populates document references.
Creates a replaceOne query: finds the first document that matches filter and replaces it with replacement.
Starts a MongoDB session for benefits like causal consistency, retryable writes, and transactions.
Makes the indexes in MongoDB match the indexes defined in this model's
schema. This function will drop any indexes that are not defined in
the model's schema except the _id index, and build any indexes that
are in your schema but not in MongoDB.
Translate any aliases fields/conditions so the final query or document object is pure
Creates a updateMany query: updates all documents that match filter with update.
Creates a updateOne query: updates the first document that matches filter with update.
Casts and validates the given object against this model's schema, passing the given context to custom validators.
Watches the underlying collection for changes using MongoDB change streams.
Creates a Query, applies the passed conditions, and returns the Query.
Generated using TypeDoc
Base Mongoose instance the model uses.