【发布时间】:2016-03-06 16:45:59
【问题描述】:
有一个 MongoDB 集合,它是一个从 Angular 资源返回的对象数组。
[{_id: "565ee3582b8981f015494cef", button: "", reference: "", text: "", title: "", …},
{_id: "565ee3582b8981f015494cf0", button: "", reference: "", text: "", title: "", …}]
我必须允许用户将一个对象插入到数组的任何索引中,并通过 Mongoose 保存到 MongoDB。
var object = {
button: "",
image: {},
reference: "",
text: "",
title: "",
};
我了解如何将对象推送到数组的末尾,但是如何指定插入的索引?
到目前为止,考虑首先创建对象:
Slide.create(object, function(result) {
console.log(result);
});
然后使用update方法更新数组中的位置:
【问题讨论】:
标签: javascript angularjs mongodb mongoose mongodb-query