相关疑难解决方法(0)

在mongodb中更新嵌套文档

假设我有一个这样的数据结构:

{
    'name': 'test',
    'anotherdoc': {
        'something': 'someval',
        'somenum': 1
    }
}
Run Code Online (Sandbox Code Playgroud)

现在,说我想要设置一些东西.最初,我会这样做:

collection.update({'_id': myid}, {$set: {'anotherdoc.something': 'somenewval'});
Run Code Online (Sandbox Code Playgroud)

然而,这似乎是不正确的.它确实在那里放了一些数据,但它以奇怪的方式实现.在这种情况下,它会像这样结束:

[
    {
        'name': 'test',
        'anotherdoc': {
            'something': 'someval',
            'somenum': 1
        }
    },
    ['anotherdoc.something', 'someval']
]
Run Code Online (Sandbox Code Playgroud)

当然,不是我想要的.

mongodb

15
推荐指数
1
解决办法
2万
查看次数

标签 统计

mongodb ×1