【问题标题】:MongoDB insert data to an existing user in NodeJSMongoDB 向 NodeJS 中的现有用户插入数据
【发布时间】:2020-08-14 18:45:08
【问题描述】:

我想问您是否可以向现有用户插入一些新数据,

没有从之前添加它们,而只是通过在模型中定义它们。

这可能吗?如果可以,怎么做?

如果您不明白其中的任何部分,请告诉我。

【问题讨论】:

  • mongo 支持 upsert 功能。您能否发布一些关于您尝试过的代码?
  • 我没有尝试过任何事情,因为我不知道这是否可行。
  • @akaphenom 我刚刚搜索过。你的意思是更新功能?

标签: node.js reactjs mongodb mongoose mern


【解决方案1】:

https://docs.mongodb.com/manual/reference/method/db.collection.update/

mongodb.someCollection.update(
  {/* some query to match the record or not */},
  {/* record to update OR record to insert if no match */},
  {
     /* options */
     upsert: true
  }
)

【讨论】:

  • 我想这就是我想要它做的事情。非常感谢,我认为这对我有用 再次感谢。
猜你喜欢
  • 2020-04-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多