![](/img/trans.png)
[英]How do I do a number ID pattern and check the ID's if they're exists or not in mongoose
[英]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.