簡體   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

我會重新問這個,“https://stackoverflow.com/questions/62547933/how-can-i-make-a-number-id-pattern-1-2-3-4-in-mongoose”,我解釋得很差在那篇文章中。 所以我想做一個像 1,2,3,4,5 這樣的數字模式,但無限。 然后如何重復“findbyID”function? 我不知道如何重復 function,如果 ID“1”存在,則 ID“2”,然后 ID“3”,然后無限繼續。 有人可以幫我解決這個問題嗎? 這是我的代碼。 (對不起,如果我的英語不好,我來自其他國家。)

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

我認為你不能像 1,2,3....infinity 那樣自己分配 id,mongoose 會自動生成一個唯一的 id,你不能操縱它,如果你想在特定的 model 中找到所有數據,你可以寫:例如: - User.find({}) 或 User.findAll() 或 User.find() 這里用戶是 model
您還可以查看 mongoose 文檔並找到各種不同的方法,您不必在 User.findbyID() function 上循環訪問所有數據有各種不同的方法

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM