简体   繁体   English

如何进行数字 ID 模式并检查 ID 是否存在于 mongoose 中

[英]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.我会重新问这个,“https://stackoverflow.com/questions/62547933/how-can-i-make-a-number-id-pattern-1-2-3-4-in-mongoose”,我解释得很差在那篇文章中。 So I want to do a number pattern like 1,2,3,4,5 but infinitly.所以我想做一个像 1,2,3,4,5 这样的数字模式,但无限。 And then how to repeat the "findbyID" function?然后如何重复“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.我不知道如何重复 function,如果 ID“1”存在,则 ID“2”,然后 ID“3”,然后无限继续。 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我认为你不能像 1,2,3....infinity 那样自己分配 id,mongoose 会自动生成一个唯一的 id,你不能操纵它,如果你想在特定的 model 中找到所有数据,你可以写:例如: - User.find({}) 或 User.findAll() 或 User.find() 这里用户是 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您还可以查看 mongoose 文档并找到各种不同的方法,您不必在 User.findbyID() function 上循环访问所有数据有各种不同的方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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