简体   繁体   中英

How do I do a number ID pattern and check the ID's if they're exists or not in mongoose

I will reask this, "https://stackoverflow.com/questions/62547933/how-can-i-make-a-number-id-pattern-1-2-3-4-in-mongoose", I poorly explained in that post. So I want to do a number pattern like 1,2,3,4,5 but infinitly. And then how to repeat the "findbyID" function? I don't know how to repeat the function that if the ID "1" exist then the ID "2" and then ID "3" and then it goes on infinitly. Could somebody help me with this? This is my code. (Sorry if my english bad, i'm from other country.)

const note = new noteModel ({
      _id: (here infinite number),
      note: 
      User:
      UserId:
    });

I think you cannot assign id's yourself like 1,2,3....infinity, mongoose automatically generates a unique id and you cannot manipulate it and if you want to find all the data in a particular model you could just write: eg:- User.find({}) or User.findAll() or User.find() here User is a model
you could also check out the mongoose docs and find various different methods too you don't have to put a loop on User.findbyID() function to access all the data there are various different methods

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM