27 Matching Annotations
  1. Jan 2024
    1. Instance methods Instances of Models are documents. Documents have many of their own built-in instance methods. We may also define our own custom document instance methods. // define a schema const animalSchema = new Schema({ name: String, type: String }, { // Assign a function to the "methods" object of our animalSchema through schema options. // By following this approach, there is no need to create a separate TS type to define the type of the instance functions. methods: { findSimilarTypes(cb) { return mongoose.model('Animal').find({ type: this.type }, cb); } } }); // Or, assign a function to the "methods" object of our animalSchema animalSchema.methods.findSimilarTypes = function(cb) { return mongoose.model('Animal').find({ type: this.type }, cb); }; Now all of our animal instances have a findSimilarTypes method available to them. const Animal = mongoose.model('Animal', animalSchema); const dog = new Animal({ type: 'dog' }); dog.findSimilarTypes((err, dogs) => { console.log(dogs); // woof }); Overwriting a default mongoose document method may lead to unpredictable results. See this for more details. The example above uses the Schema.methods object directly to save an instance method. You can also use the Schema.method() helper as described here. Do not declare methods using ES6 arrow functions (=>). Arrow functions explicitly prevent binding this, so your method will not have access to the document and the above examples will not work.

      Certainly! Let's break down the provided code snippets:

      1. What is it and why is it used?

      In Mongoose, a schema is a blueprint for defining the structure of documents within a collection. When you define a schema, you can also attach methods to it. These methods become instance methods, meaning they are available on the individual documents (instances) created from that schema.

      Instance methods are useful for encapsulating functionality related to a specific document or model instance. They allow you to define custom behavior that can be executed on a specific document. In the given example, the findSimilarTypes method is added to instances of the Animal model, making it easy to find other animals of the same type.

      2. Syntax:

      Using methods object directly in the schema options:

      javascript const animalSchema = new Schema( { name: String, type: String }, { methods: { findSimilarTypes(cb) { return mongoose.model('Animal').find({ type: this.type }, cb); } } } );

      Using methods object directly in the schema:

      javascript animalSchema.methods.findSimilarTypes = function(cb) { return mongoose.model('Animal').find({ type: this.type }, cb); };

      Using Schema.method() helper:

      javascript animalSchema.method('findSimilarTypes', function(cb) { return mongoose.model('Animal').find({ type: this.type }, cb); });

      3. Explanation in Simple Words with Examples:

      Why it's Used:

      Imagine you have a collection of animals in your database, and you want to find other animals of the same type. Instead of writing the same logic repeatedly, you can define a method that can be called on each animal instance to find similar types. This helps in keeping your code DRY (Don't Repeat Yourself) and makes it easier to maintain.

      Example:

      ```javascript const mongoose = require('mongoose'); const { Schema } = mongoose;

      // Define a schema with a custom instance method const animalSchema = new Schema({ name: String, type: String });

      // Add a custom instance method to find similar types animalSchema.methods.findSimilarTypes = function(cb) { return mongoose.model('Animal').find({ type: this.type }, cb); };

      // Create the Animal model using the schema const Animal = mongoose.model('Animal', animalSchema);

      // Create an instance of Animal const dog = new Animal({ type: 'dog', name: 'Buddy' });

      // Use the custom method to find similar types dog.findSimilarTypes((err, similarAnimals) => { console.log(similarAnimals); }); ```

      In this example, findSimilarTypes is a custom instance method added to the Animal schema. When you create an instance of the Animal model (e.g., a dog), you can then call findSimilarTypes on that instance to find other animals with the same type. The method uses the this.type property, which refers to the type of the current animal instance. This allows you to easily reuse the logic for finding similar types across different instances of the Animal model.

      Certainly! Let's go through each part and explain it in simple terms: ### 1. `this` in Mongoose: - **What is `this`?** In JavaScript, `this` refers to the current context or object. In Mongoose, particularly within methods and middleware functions, `this` represents the instance (document) the function is currently operating on. - **Why is it used?** `this` is used to access and modify the properties of the current document. For example, in a Mongoose method, `this` allows you to refer to the fields of the specific document the method is called on. ### 2. Example: Let's use the `userSchema.pre("save", ...)`, which is a Mongoose middleware, as an example: ```javascript userSchema.pre("save", async function (next) { if (!this.isModified("password")) { next(); } else { this.password = await bcrypt.hash(this.password, 10); next(); } }); ``` - **Explanation in Simple Words:** - Imagine you have a system where users can sign up and set their password. - Before saving a new user to the database, you want to ensure that the password is securely encrypted (hashed) using a library like `bcrypt`. - The `userSchema.pre("save", ...)` is a special function that runs automatically before saving a user to the database. - In this function: - `this.isModified("password")`: Checks if the password field of the current user has been changed. - If the password is not modified, it means the user is not updating their password, so it just moves on to the next operation (saving the user). - If the password is modified, it means a new password is set or the existing one is changed. In this case, it uses `bcrypt.hash` to encrypt (hash) the password before saving it to the database. - The use of `this` here is crucial because it allows you to refer to the specific user document that's being saved. It ensures that the correct password is hashed for the current user being processed. In summary, `this` in Mongoose is a way to refer to the current document or instance, and it's commonly used to access and modify the properties of that document, especially in middleware functions like the one demonstrated here for password encryption before saving to the database.

    Tags

    Annotators

    URL

  2. Nov 2022
  3. May 2022
  4. Sep 2021
    1. Update API usage of the view helpers by changing javascript_packs_with_chunks_tag and stylesheet_packs_with_chunks_tag to javascript_pack_tag and stylesheet_pack_tag. Ensure that your layouts and views will only have at most one call to javascript_pack_tag or stylesheet_pack_tag. You can now pass multiple bundles to these view helper methods.

      Good move. Rather than having 2 different methods, and requiring people to "go out of their way" to "opt in" to using chunks by using the longer-named javascript_packs_with_chunks_tag, they changed it to just use chunks by default, out of the box.

      Now they don't need 2 similar but separate methods that do nearly the same, which makes things simpler and easier to understand (no longer have to stop and ask oneself, which one should I use? what's the difference?).

      You can't get it "wrong" now because there's only one option.

      And by switching that method to use the shorter name, it makes it clearer that that is the usual/common/recommended way to go.

  5. Jun 2021
  6. May 2021
  7. Apr 2021
  8. Jun 2020
  9. May 2020
    1. Sometimes plugins can conflict with a theme or with each other.  Disable all your plugins and see if the problem persists. If everything is working once the plugins were disabled it means there's a conflict with a plugin or maybe even a set of plugins. Enable the plugins one by one to identify the one that is creating the conflict.
    1. Right click on the /wp-content/plugins folder and rename it plugins.old. This will deactivate all of the plugins. In most cases, this will also lock the WordPress admin area as well.  You will still be able to perform these steps from within the File Manager.Reactivate the plugins folder by following the above instructions and renaming the folder plugins. This will allow you to reactivate each plugin individually to isolate the offending plugin and resolve the 500 Internal Server Error.  This should also allow access to the WordPress Dashboard again. From the WordPress Dashboard: Reactivate each plugin (one at a time) and refresh the website to see if the issue has been resolved.
  10. Feb 2019
    1. For they who are born deaf, can make themselves understood by visible signs; and we have it on the best authority, that the Mimes of the Ancients, were perfectly intelli-gible, without the use of words.

      Sheridan looks for a definition of language that holds weight across multiple types of humans and cultural techniques (people who are deaf, mimes, the literate). Is he then perhaps exploring the question "which languages?" instead of "what is language?"

    1. they need only peruse what they've Writ, and consider whether they wou'd express 'cmsclvcs thus in Conversation

      And what of those who cannot see/sense writing in the same way they sense speech? What cut is she making here in ability?

    1. master a multiple, diversified, almost boundless domain of culture.

      Another apparatus (printing) which greatly opens up our understanding of the world and our access to others, allowing us to ask the question "which one?"

    1. affect the mind of a peasant or Indian with lhe highest admiration

      Another set of cuts here (and with the "person, familiarized to superior beauties").

      Those who have limited exposure to observe or practice (and thereby to increase refinement of taste) are in another category altogether.

      Who is cut off by the inability to increase taste and whose voices are silenced?

    2. sound and a defective state

      And who/what determines those states? Where are the cuts made between the two?

    1. an imperfection rather upon our words than understandings

      Hm, okay. So what I took (above) as comments on humanity, Locke is saying are comments on language. (Or is it both?)

    2. ideas, which are also universally the same

      I already have a problem.

      Is sensation a universal phenomenon? If so, that doesn't mean that human's experience sensations in the same way and therefore the ideas generated from those sensations would naturally vary.

      The desire for "universal" anything seems fraught with problem, even for seemingly "simple" ideas.

    3. incomplete or inaccurate idea

      Incomplete or inaccurate according to whom? Some objective Truth?

    1. 011 1/w Ed11catio11 of Girls (published in 1687),

      Cf. Wollstonecraft's Vindication of the Rights of Woman, written about 100 years later, making a similar argument. Specifically, Wollstonecraft argues that women are not naturally inferior or frivolous but have been bred that way through poor education. Taken in comparison to the Enlightenment's exploration of human nature and with a lack of significant progress between 1687 and 1792 (outside of literacy, noted below), it seems clear that "human nature" really means "man's nature."

    2. fundamental

      Which "fundaments"? What foundations are the ones that "all people" start with?

    3. he study of "man," as Pope and his classical forebear Horace put it, to be the proper activity of the poet.

      Cf. Le Guin's hero-killer story

      What other stories were lost under this focus?

    4. We all value one another M> much

      And who, precisely, does he count as "one another"?

  11. Jan 2019
    1. nature—as opposed to cul-ture—is ahistorical and timeless?

      Doreen Massey has an interesting book that touches on this (Space, Place, and Gender), where she points out that time and space are treated as binaries, where time is typically masculine and dynamic and space is feminine and static. Nature (gendered feminine) is spatial, a place, and therefore not a time ("ahistorical and timeless"). Culture, on the other hand, is temporal, dynamic, masculine. It's a very particular rhetoric which begs the "which one?" question.

      (While Massey points out this common way of conceiving of time/space and binaries in general [A vs. Not A], she argues that the concept of space needs to be defined on its own merit, distinct from its binary opposite.)

    2. as if Nature isa container.

      Why does Kirby reject the notion of Nature as container? Is she posing containers as inert objects, 'mere' holders? Cf. Le Guin's notion of the container as another type of story.

  12. Mar 2015
    1. an objective set for the Sprint that can be met through the implementation of Product Backlog. It provides guidance to the Development Team on why it is building the Increment. It is created during the Sprint Planning meeting. The Sprint Goal gives the Development Team some flexibility regarding the functionality implemented within the Sprint. The selected Product Backlog items deliver one coherent function, which can be the Sprint Goal. The Sprint Goal can be any other coherence that causes the Development Team to work together rather than on separate initiatives.

      an objective set for the Sprint that can be met through the implementation of Product Backlog. It provides guidance to the Development Team on why it is building the Increment. It is created during the Sprint Planning meeting. The Sprint Goal gives the Development Team some flexibility regarding the functionality implemented within the Sprint. The selected Product Backlog items deliver one coherent function, which can be the Sprint Goal. The Sprint Goal can be any other coherence that causes the Development Team to work together rather than on separate initiatives.