Python-Pymongo MongoDB 3.4-NumberDecimal [英] Python - Pymongo MongoDB 3.4 - NumberDecimal

查看:424
本文介绍了Python-Pymongo MongoDB 3.4-NumberDecimal的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用mongodb 3.4以便向数据库中插入适当的价格。

i am using mongodb 3.4 in order to insert proper prices to my database..

根据:

https://github.com/mongodb/specifications/blob/master/source/bson-decimal128/decimal128.rst#reading-from-extended-json

我在我的python代码中使用了此代码:

i used this in my python code:

'credits': {'$numberDecimal': Decimal128('9.99')},

但是抛出:

bson.errors.InvalidDocument: key '$numberDecimal' must not start with '$'

那么使用python在mongodb中插入数字十进制的正确语法是什么?

So what is the correct syntax for inserting numberdecimal in mongodb using python ?

感谢和问候

推荐答案

简单地说:

collection.insert_one({'credits': Decimal128('9.99')})

( $ numberDecimal语法用于在JSON字符串中表示一个十进制数字。但是您根本不使用JSON。)

(The "$numberDecimal" syntax is for expressing a decimal number within a JSON string. But you're not using JSON at all.)

这篇关于Python-Pymongo MongoDB 3.4-NumberDecimal的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆