小编pow*_*xie的帖子

bson.errors.InvalidDocument: key '$numberDecimal' 在使用 json 时不能以 '$' 开头

我有一个小的 json 文件,有以下几行:

{
    "IdTitulo": "Jaws",
    "IdDirector": "Steven Spielberg",
    "IdNumber": 8,
    "IdDecimal": "2.33"
}
Run Code Online (Sandbox Code Playgroud)

我的数据库集合中有一个模式,名为 test_dec。这是我用来创建架构的内容:

db.createCollection("test_dec",
{validator: {
    $jsonSchema: {
         bsonType: "object",
         required: ["IdTitulo","IdDirector"],
         properties: {
         IdTitulo: {
                "bsonType": "string",
                "description": "string type, nombre de la pelicula"
            },
         IdDirector: {
                "bsonType": "string",
                "description": "string type, nombre del director"
            },
        IdNumber : {
                "bsonType": "int",
                "description": "number type to test"
            },
        IdDecimal : {
                 "bsonType": "decimal",
                 "description": "decimal type"
                    }
       }
    }}
    })
Run Code Online (Sandbox Code Playgroud)

我已经多次尝试插入数据。问题出在 IdDecimal 字段值中。

一些试验,将 IdDecimal 行替换为:

 "IdDecimal": …
Run Code Online (Sandbox Code Playgroud)

python json mongodb bson

6
推荐指数
1
解决办法
552
查看次数

Remove an element from nested lists with mixed structures (lists and integers) in Python

Consider the lists:

assigned = [4,8]
matching = [['B', [4, 5, 6]], ['C', [7, 8, 9]]]
Run Code Online (Sandbox Code Playgroud)

I am trying to remove given integers with the following code

for ii in range(len(assigned)):
    while any(assigned[ii] in x for x in matching):
        matching.remove(assigned[ii])
Run Code Online (Sandbox Code Playgroud)

I have two problems here. First one is to get into the inner lists. Right now the code does nothing because there is no matching.

Second problem, I tried this:

t = ['B', [4, 5, 6]]
if any(4 in x …
Run Code Online (Sandbox Code Playgroud)

python nested-lists

4
推荐指数
1
解决办法
59
查看次数

标签 统计

python ×2

bson ×1

json ×1

mongodb ×1

nested-lists ×1