Mongodb语句类型错误 [Error] invalid document for insert: keys cannot begin with "$": "$numberDecimal"
这个是Mongodb 驱动API给出的可执行日志, 但在mongo shell终端执行,却报错。
只能说Mongodb的API设计太差了,自己的格式都不能兼容。累的就是一线的使用者。
db.orders.insertMany([{"_id": 10210, "name": "mongodb10", "total": {"$numberDecimal": "10.1"}, "num": 10, "abc": "test bee "},{"_id": 10211, "name": "mongodb11", "total": {"$numberDecimal": "11.11"}, "num": 11, "abc": "test bee "}])
错误信息:
> [Error] invalid document for insert: keys cannot begin with "$": "$numberDecimal"
at line 1, column 1
> 时间: 0.001s
https://www.mongodb.com/docs/manual/reference/mongodb-extended-json/#type-representations
"int32field": | {"$numberInt":"10"} | 10 |
"int64Field": | {"$numberLong":"50"} | 50 |
"doubleField": | {"$numberDouble":"10.5"} | 10.5 |
使用专业的Mongodb ORM工具,可以避免这个问题:
https://gitee.com/automvc/bee-exam/tree/master/src/main/java/org/teasoft/exam/bee/mongodb
直接运行,输出的日志,即可在mongo shell运行, 调试更方便。