【发布时间】:2019-08-22 19:58:55
【问题描述】:
如何在 mongodb 中传递多个参数
我目前的设置是这样的:
const query = (...query) => {
let newQuery = query // this is an array
Model.findByIdAndUpdate(newQuery) // nothing happen coz the value is array
}
query(id, {name:'json bourne'})
我想传递查询中的所有参数。谢谢
原来的查询是这样的
Model.findByIdAndUpdate(id, { name: 'jason bourne' })
就是这样传递参数
let newQuery =
id, { name: 'jason bourne'}// this will not work also it on get the first item which is id
Model.findByIdAndUpdate(newQuery)
【问题讨论】:
-
为什么不只是
{ id, name: 'json bourne'}? -
这不能作为 id 工作,并且 name 是一个单独的对象,请参阅mongoosejs.com/docs/api.html#model_Model.findByIdAndUpdate
-
您的问题不言自明,请解释清楚,以便我们为您提供帮助
-
这里是原查询
Model.findByIdAndUpdate(id, { name: 'jason bourne' }) -
那么告诉我你到底想用这个做什么
标签: javascript mongodb mongoose mongodb-query