繁体   English   中英

如何在 mongoose 中制作数字 id 模式 1、2、3、4

[英]How can I make a number id pattern 1, 2, 3, 4 in mongoose

我如何制作这样的图案? 我无法编写代码,因为我是新手。

这是我的代码

array = 1,2,3,4,5

const note = new notedModel ({
      _id: array,
      note: args[1],

});

如果您要求,也可以使用其他模块。

我希望它会有所帮助

const array = [1,2,3,4,5];

const notes = array.map(element => new notedModel({
    _id: element,
    note: args[1], // or maybe args[element] if you need to select arg by array's element 
}));

PS您可以在此处阅读答案以小心使用 id: How do you implement an auto-incrementing primary ID in MongoDB?

我希望这有帮助

 class NotedModel{ constructor(id, arg){ this._id = id this._note = arg } } var arr = [1, 2, 3, 4, 5] var note = []; for(i = 0; i < arr.length; i++){ note.push(new NotedModel(arr[i], i)); } console.log(note);

暂无
暂无

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

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