mongodb数组值中的元素按顺序保存
PHP中文网
PHP中文网 2017-04-24 09:09:52
0
3
508

比如我有个值已经保存在mongodb中

[
    1,
    2,
    5,
    4,
    3,
    ...
]

想更新成这样

[
    1,
    2,
    3,
    4,
    5,
    ...
]

怎么搞效率最高, 假设这个数组的内容大约100k, 有上千元素

PHP中文网
PHP中文网

认证0级讲师

reply all(3)
PHPzhong

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}})

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template