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"} |
5 |

文章讨论了在使用MongoDBAPI时遇到的文档插入错误,特别是键不能以$开头的问题,如$numberDecimal。虽然在MongoShell中也会报错,但作者推荐使用特定的MongoDBORM工具,如Bee-Exam,以避免此类问题并提高调试效率。
最低0.47元/天 解锁文章
6543

被折叠的 条评论
为什么被折叠?



