Return mongoose result in a function

Jeremy M.

I'm trying to return a result from my mongoose find operation. I know a lot of question have already been asked for this but i think this is different. Here's my user :

var UserSchema = new mongoose.Schema({
    variable: {type: mongoose.Schema.ObjectId, ref: 'Variable'}
});

My user have a method to retrieve his variable. Here's the problem.

UserSchema.methods.getVariable = function()  {
   //TODO ?
}

I don't know how to populate my field and then return the result of the populate...

HMR

I think you can just use populate

var UserSchema = new mongoose.Schema({
  variable: {type: mongoose.Schema.ObjectId, ref: 'Variable'}
});

UserSchema.
  findOne({your:"query"}).
  populate('variable').
  exec().
  then(
    user=>console.log("user is:",user)
  );

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Return result to parent function

From Dev

Return result of Action to Function

From Dev

wrapAsync return function not result

From Dev

Mongoose geo query does not return correct result

From Dev

Return stored procedure result in function

From Dev

How to get function return result?

From Dev

excel VBA return result of function

From Dev

C - function to return curved result

From Dev

Return select * result in postgres function

From Dev

Creating a function to return boolean result?

From Dev

Where to return result of recursive function

From Dev

Return a array of result from function

From Dev

How to get function return result?

From Dev

return function result to output argument

From Dev

Undefined return value mongoose / nodejs recursive function

From Dev

Is there any purpose to return the result of a function in an empty function?

From Dev

Mongoose - always return null instead of an error when no result found?

From Dev

Mongoose - always return null instead of an error when no result found?

From Dev

PHP function shows result but does not return it

From Dev

DCOUNT function doesn't return the correct result

From Dev

Bind a lambda to a function to get return result

From Dev

how to pass result of $.get to return of another function

From Dev

How to return dereferenced value as a result of a function in Clojure

From Dev

SAS Macro function return SQL result

From Dev

Return result disappears in Python recursive function

From Dev

How to return a failure inside .map function in a Result

From Dev

How to return the onclick function is result to href in javascript?

From Dev

Access return value from result() function

From Dev

php looping a function and return result to original call

Related Related

  1. 1

    Return result to parent function

  2. 2

    Return result of Action to Function

  3. 3

    wrapAsync return function not result

  4. 4

    Mongoose geo query does not return correct result

  5. 5

    Return stored procedure result in function

  6. 6

    How to get function return result?

  7. 7

    excel VBA return result of function

  8. 8

    C - function to return curved result

  9. 9

    Return select * result in postgres function

  10. 10

    Creating a function to return boolean result?

  11. 11

    Where to return result of recursive function

  12. 12

    Return a array of result from function

  13. 13

    How to get function return result?

  14. 14

    return function result to output argument

  15. 15

    Undefined return value mongoose / nodejs recursive function

  16. 16

    Is there any purpose to return the result of a function in an empty function?

  17. 17

    Mongoose - always return null instead of an error when no result found?

  18. 18

    Mongoose - always return null instead of an error when no result found?

  19. 19

    PHP function shows result but does not return it

  20. 20

    DCOUNT function doesn't return the correct result

  21. 21

    Bind a lambda to a function to get return result

  22. 22

    how to pass result of $.get to return of another function

  23. 23

    How to return dereferenced value as a result of a function in Clojure

  24. 24

    SAS Macro function return SQL result

  25. 25

    Return result disappears in Python recursive function

  26. 26

    How to return a failure inside .map function in a Result

  27. 27

    How to return the onclick function is result to href in javascript?

  28. 28

    Access return value from result() function

  29. 29

    php looping a function and return result to original call

HotTag

Archive