How to use Symbols with Mongoose model?

Richard Rublev

I looked everywhere not only SO,but couldn't find the answer. I found this mongoose-model-ES6. I am trying to use Symbol data type. so the previous link does not help.

My class looks like this

import mongoose from 'mongoose';

const _user_key = Symbol('key');
const _user_name = Symbol('name');
const _user_email = Symbol('email');

class User extends mongoose.Schema {
    constructor(key,name,email) {
        const user = super({
            this[_user_key] = key;
            this[_user_name] = name;
            this[_user_email] = email;              
        })        
    }
get key () {return this[_user_key]};
get name (){return this[_user_name]};
get email () {return this[_user_email]};    
};

export default mongoose.model('User', new User);

I run from terminal

            this[_user_key] = key;
                ^

SyntaxError: Unexpected token '['
    at Loader.moduleStrategy (internal/modules/esm/translators.js:122:18)
    at async link (internal/modules/esm/module_job.js:42:21)

If I try what Bergi suggested

class User extends mongoose.Schema {
    constructor(key,name,email) {
        const user = super(
            this[_user_key] = key;
            this[_user_name] = name;
            this[_user_email] = email;              
        )        
    }

I got error

            this[_user_key] = key;
                              ^^^

SyntaxError: missing ) after argument list
36ve

The error does not look related to symbols but to an actual syntax error

Did you mean

super({
  [_user_key]   : key,
  [_user_name]  : name,
  [_user_email] : email,             
})        

?

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to query nested data in mongoose model

分類Dev

R: how to use symbols as a FUN for apply?

分類Dev

how to use mongoose pagination with populate and query

分類Dev

how does one update numbers inside mongoose model nested array

分類Dev

How to I get the results of a call to a method that is located in a Mongoose model?

分類Dev

How to use regular expressions to deal with Chinese punctuation symbols in C++

分類Dev

How to use the custom model in MVC

分類Dev

Express cookieSession and Mongoose: how can I make request.session.user be a Mongoose model?

分類Dev

Retrieving model using mongoose

分類Dev

how to filter model.find query results with model.populate query results in mongoose?

分類Dev

How to use mongoose to return field from object array in string array

分類Dev

How to use model types between projects?

分類Dev

How to correctly use an intermediate layer of a vgg model

分類Dev

How to use linux device model and /sys filesystem?

分類Dev

How can I use VBA to format Symbols / Icons into cells without using conditional formatting

分類Dev

How to use CardIO and Paypal-iOS-sdk in the same project (Duplicate Symbols)

分類Dev

Rlang: how to treat strings as symbols

分類Dev

How to identify visual studio symbols?

分類Dev

How to change the Keyboard Symbols and Numbers?

分類Dev

Mongoose Deep Populate limiting intermediate model

分類Dev

Getting mongoose not defined error in model file

分類Dev

Can't Catch Error for Mongoose Model Save

分類Dev

Good practice for parent model field udpate with mongoose

分類Dev

Mongoose Model, cleaning/parsing an Array efficiently

分類Dev

How to use a previously trained model to get labels of images - TensorFlow

分類Dev

How to best use zipcodes in Random Forest model training?

分類Dev

How can I use filter in ng-model AngularJS

分類Dev

How can i use my mnist trained model to predict an image

分類Dev

How do I use knn model for new data in R?

Related 関連記事

  1. 1

    How to query nested data in mongoose model

  2. 2

    R: how to use symbols as a FUN for apply?

  3. 3

    how to use mongoose pagination with populate and query

  4. 4

    how does one update numbers inside mongoose model nested array

  5. 5

    How to I get the results of a call to a method that is located in a Mongoose model?

  6. 6

    How to use regular expressions to deal with Chinese punctuation symbols in C++

  7. 7

    How to use the custom model in MVC

  8. 8

    Express cookieSession and Mongoose: how can I make request.session.user be a Mongoose model?

  9. 9

    Retrieving model using mongoose

  10. 10

    how to filter model.find query results with model.populate query results in mongoose?

  11. 11

    How to use mongoose to return field from object array in string array

  12. 12

    How to use model types between projects?

  13. 13

    How to correctly use an intermediate layer of a vgg model

  14. 14

    How to use linux device model and /sys filesystem?

  15. 15

    How can I use VBA to format Symbols / Icons into cells without using conditional formatting

  16. 16

    How to use CardIO and Paypal-iOS-sdk in the same project (Duplicate Symbols)

  17. 17

    Rlang: how to treat strings as symbols

  18. 18

    How to identify visual studio symbols?

  19. 19

    How to change the Keyboard Symbols and Numbers?

  20. 20

    Mongoose Deep Populate limiting intermediate model

  21. 21

    Getting mongoose not defined error in model file

  22. 22

    Can't Catch Error for Mongoose Model Save

  23. 23

    Good practice for parent model field udpate with mongoose

  24. 24

    Mongoose Model, cleaning/parsing an Array efficiently

  25. 25

    How to use a previously trained model to get labels of images - TensorFlow

  26. 26

    How to best use zipcodes in Random Forest model training?

  27. 27

    How can I use filter in ng-model AngularJS

  28. 28

    How can i use my mnist trained model to predict an image

  29. 29

    How do I use knn model for new data in R?

ホットタグ

アーカイブ