【发布时间】:2020-12-10 17:16:04
【问题描述】:
假设我在 MongoDB 中插入数据
db.collection.insertMany([{username:'Jack',msg:'hello'},{username:'Jenny',msg:'hello world'},{username:'Rose',msg:'Hi howz You'}])
现在我希望这样插入数据:
{account_username:'Jack',msg:'hello'}
{account_username:'Jenny',msg:'hello world'}
{account_username:'Rose',msg:'Hi howz You'}
不是这个:
{username:'Jack',msg:'hello'}
{username:'Jenny',msg:'hello world'}
{username:'Rose',msg:'Hi howz You'}
我在我的 NodeJS 代码中使用 mongoose,我可以在 Schema 中做一些事情,所以只要输入是用户名,它就会自动引用我定义的 mongoose Schema 的 account_username。
【问题讨论】:
标签: node.js mongodb mongoose mongodb-query mongoose-schema