比如我有个值已经保存在mongodb中
[ 1, 2, 5, 4, 3, ... ]
想更新成这样
[ 1, 2, 3, 4, 5, ... ]
怎么搞效率最高, 假设这个数组的内容大约100k, 有上千元素
认证0级讲师
Use aggregate, unwind first, and then use sort.
Take it out and sort it in the code, then set it back. There is no transaction for writing in mongo, and a large number of database operations are not recommended
I think you can do this:
db.test.update({}, {$set:{"key.2":4, "key.3":3}})
Use aggregate, unwind first, and then use sort.
Take it out and sort it in the code, then set it back. There is no transaction for writing in mongo, and a large number of database operations are not recommended
I think you can do this: