[英]Update in PyMongo with "." in key
I have to find the value of attribute "8.jpg" in collection with "job_id":"0".我必须在“job_id”:“0”的集合中找到属性“8.jpg”的值。 I have written the following query.
我写了以下查询。 "8.jpg" is an Object type.
“8.jpg”是对象类型。
db.collection.findOne({"job_id":"0"})."8.jpg"
I am getting following error: 2020-10-11T23:18:39.812+0530 E QUERY [thread1] SyntaxError: missing name after . operator @(shell):1:42
我收到以下错误:
2020-10-11T23:18:39.812+0530 E QUERY [thread1] SyntaxError: missing name after . operator @(shell):1:42
2020-10-11T23:18:39.812+0530 E QUERY [thread1] SyntaxError: missing name after . operator @(shell):1:42
Also how to find the type of an attribute?另外如何找到属性的类型?
I am also trying to update a key in attribute "8.jpg" db.collection.update({"job_id": "0"},{ $set:{"8.jpg.name":"abc"}})
but this is coming all wrong我还试图更新属性“8.jpg”中的一个键
db.collection.update({"job_id": "0"},{ $set:{"8.jpg.name":"abc"}})
但这一切都错了
You getting this error because you are doing ."8.jpg"
.您收到此错误是因为您正在执行
."8.jpg"
。 you can not have a string after a dot operator.点运算符后不能有字符串。
You can try this:你可以试试这个:
db.collection.findOne({"job_id":"0"})["8.jpg"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.