SHARE
TWEET

Untitled

a guest Oct 21st, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const mongoose = require("mongoose");
  2. const Schema = mongoose.Schema;
  3.  
  4. const userScheme = new Schema({
  5.     name: String,
  6.     age: Number
  7. });
  8.  
  9. mongoose.connect("mongodb://localhost:27017/my", { useNewUrlParser: true });
  10.  
  11. const User = mongoose.model("User", userScheme);
  12. const user = new User({
  13.     name: String,
  14.     age: Number
  15. });
  16.  
  17. // проблема
  18. function CheckCount(): string {
  19.     let my: string = "";
  20.      User.count({}, function test(err: any, docs: string){
  21.        // mongoose.disconnect();
  22.          
  23.        // if(err) return console.log(err);
  24.          
  25.        // console.log(docs);
  26.       //  return docs;
  27.         my = docs;
  28.         console.log(my);
  29.     });    
  30.     console.log(my);
  31.     return my;
  32. }
  33.  
  34. console.log(CheckCount());
  35.  
  36. // работает
  37. User.count({}, function(err: any, docs: any){
  38.     mongoose.disconnect();
  39.      
  40.     if(err) return console.log(err);
  41.      
  42.     console.log(docs);
  43. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top