显示所有可能性? (是或否)

时间:2017-11-23 17:21:29

标签: database mongodb insert nosql

我创建了此代码,以便在TPC-H schema中创建MongoDB,并进行一些验证:

db.createCollection("lineItem", {
  validator: {
    $or: [
      {
        "lineNumber": { $type: "int"}      
      },
      {
        "quantity": { $type: "decimal"}      
      },
      {
        "extendedPrice": { $type: "decimal"}      
      },
      {
        "discount": { $type: "decimal"}      
      },
      {
        "tax": { $type: "decimal"}      
      },
      {
        "returnFlag": { $type: "string"}      
      },
      {
        "lineStatus": { $type: "string"}      
      },
      {
        "shipDate": { $type: "string"}      
      },
      {
        "commitDate": { $type: "string"}      
      },
      {
        "receiptDate": { $type: "string"}      
      },
      {
        "shipInstruct": { $type: "string"}      
      },
      {
        "shipMode": { $type: "string"}      
      },
      {
        "comment": { $type: "string"}      
      },
      {
        "order.orderKey": { $type: "int", $exists: true}      
      },
      {
        "order.orderStatus": { $type: "string"}      
      },
      {
        "order.totalPrice": { $type: "decimal"}      
      },
      {
        "order.orderDate": { $type: "string"}
      },
      {
        "order.orderPriority": { $type: "string"}      
      },
      {
        "order.clerk": { $type: "string"}      
      },
      {
        "order.shipPriority": { $type: "int"}      
      },
      {
        "order.comment": { $type: "string"}      
      },
      {
        "order.customer.custKey": { $type: "int", $exists: true}      
      },
      {
        "order.customer.name": { $type: "string"}      
      },
      {
        "order.customer.address": { $type: "string"}      
      },
      {
        "order.customer.phone": { $type: "string"}      
      },
      {
        "order.customer.acctBal": { $type: "decimal"}      
      },
      {
        "order.customer.mktSegment": { $type: "string"}      
      },
      {
        "order.customer.comment": { $type: "string"}      
      },
      {
        "order.customer.nation.nationKey": { $type: "int", $exists: true}      
      },
      {
        "order.customer.nation.name": { $type: "string"}      
      },
      {
        "order.customer.nation.comment": { $type: "string"}      
      },
      {
        "order.customer.nation.region.regionKey": { $type: "int", $exists: true}      
      },
      {
        "order.customer.nation.region.regionName": { $type: "string"}      
      },
      {
        "order.customer.nation.region.comment": { $type: "string"}
      },
      {
        "partSupp.availQty": { $type: "int"}      
      },
      {
        "partSupp.supplyCost": { $type: "decimal"}      
      },
      {
        "partSupp.comment": { $type: "string"}      
      },
      {
        "partSupp.part.partKey": { $type: "int", $exists: true}      
      },
      {
        "partSupp.part.name": { $type: "string"}      
      },
      {
        "partSupp.part.mfgr": { $type: "string"}      
      },
      {
        "partSupp.part.brand": { $type: "string"}      
      },
      {
        "partSupp.part.type": { $type: "string"}      
      },
      {
        "partSupp.part.size": { $type: "int"}      
      },
      {
        "partSupp.part.container": { $type: "string"}      
      },
      {
        "partSupp.part.retailPrice": { $type: "decimal"}      
      },
      {
        "partSupp.part.comment": { $type: "string"}      
      },
      {
        "partSupp.supplier.suppKey": { $type: "int", $exists: true}      
      },
      {
        "partSupp.supplier.name": { $type: "string"}      
      },
      {
        "partSupp.supplier.address": { $type: "string"}      
      },
      {
        "partSupp.supplier.phone": { $type: "string"}      
      },
      {
        "partSupp.supplier.acctBal": { $type: "decimal"}      
      },
      {
        "partSupp.supplier.comment": { $type: "string"}      
      },
      {
        "partSupp.supplier.nation.nationKey": { $type: "int", $exists: true}      
      },
      {
        "partSupp.supplier.nation.name": { $type: "string"}      
      },
      {
        "partSupp.supplier.nation.comment": { $type: "string"}      
      },
      {
        "partSupp.supplier.nation.region.regionKey": { $type: "int", $exists: true}      
      },
      {
        "partSupp.supplier.nation.region.regionName": { $type: "string"}      
      },
      {
        "partSupp.supplier.nation.region.comment": { $type: "string"}
      }
    ]
  }
})

它运行良好(我认为),但是,我在为上面这个集合创建插入代码时遇到了一些麻烦。这是我试图插入的内容:

db.lineItem.insertOne({
    "lineNumber": 1,
    "quantity": 17,
    "extendedPrice": 24710.35,
    "discount": 0.04,
    "tax": 0.02,
    "returnFlag": "N",
    "lineStatus": "O",
    "shipDate": "1996-03-13",
    "commitDate": "1996-02-12",
    "receiptDate": "1996-03-22",
    "shipInstruct": "DELIVER IN PERSON",
    "shipMode": "TRUCK",
    "comment": "egular courts above the",
    "order": {
        "orderKey": 1,
        "orderStatus": "O",
        "totalPrice": 172799.49,
        "orderDate": "1996-01-02",
        "orderPriority": "5-LOW",
        "clerk": "Clerk#000000951",
        "shipPriority": 0,
        "comment": "nstructions sleep furiously among ",
        "customer": {
            "custKey": 370,
            "name": "Customer#000000370",
            "address": "oyAPndV IN",
            "phone": "22-524-280-8721",
            "acctBal": 8982.79,
            "mktSegment": "FURNITURE",
            "comment": "ges. final packages haggle quickly. slyly bold ",
            "nation": {
                "nationKey": 12,
                "name": "JAPAN",
                "comment": "ously. final",
                "region": {
                    "regionKey": 2,
                    "regionName": "ASIA",
                    "comment": "ges. thinly even pinto beans ca"
                }
            }
        }
    },
    "partSupp": {
        "availQty": 7030,
        "supplyCost": 802.33,
        "comment": "p about the enticingly quiet pinto beans. furiously ironic packages are care",
        "part": {
            "partKey": 1552,
            "name": "plum chartreuse sky pale firebrick",
        "mfgr": "Manufacturer#4",
            "brand": "Brand#41",
            "type": "SMALL POLISHED TIN",
            "size": 10,
            "container": "WRAP CASE",
            "retailPrice": 1453.55,
            "comment": "onic deposits"
        },
        "supplier": {
            "suppKey": 93,
            "name": "Supplier#000000093",
            "address": "wd1djjKXT4zBm",
            "phone": "26-528-528-1157",
            "acctBal": 368.76,
            "comment": "yly final accounts could are carefully. fluffily ironic instruct",
            "nation": {
                "nationKey": 16,
                "name": "MOZAMBIQUE",
                "comment": "s. ironic",
                "region": {
                    "regionKey": 0,
                    "regionName": "AFRICA",
                    "comment": "lar deposits. blithely final packages cajole. regular waters are final requests. regular accounts are according to"
                }
            }
        }
    }
});

但是,在我尝试运行它之前,MongoDB控制台显示供应商使用以下代码:

... "supplier": { 
... Display all 173 possibilities? (y or n)

当我在此集合中插入并运行find()时,supplier没有suppKey并且在其中显示ane而不是name < / p>

我已经看到this问题,询问同样的问题,但是,我没有提到这些空间。

我应该怎样做才能停止接收此错误?

1 个答案:

答案 0 :(得分:0)

'> db.staffList.insert(... (已删除代码)
显示所有175种可能性? (是或否)

尝试将代码复制到MS Word中,然后按按钮打开隐藏的字符。

在Excel中创建代码后,我遇到了同样的问题。该代码到处都是标签。移除这些标签,它应该有更好的工作机会。

(要摆脱Word中的制表符,请将^ t替换为空白。)

希望这会有所帮助。