Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

数据库更新失败 #6

Closed
Kay-iu opened this issue Jan 4, 2021 · 2 comments
Closed

数据库更新失败 #6

Kay-iu opened this issue Jan 4, 2021 · 2 comments

Comments

@Kay-iu
Copy link

Kay-iu commented Jan 4, 2021

$result = $this->db->collection('xxx')->updateOne(['_id'=> ‘xxxxx’], ['$set'=> ['fd'=> 'xxxx']]);

这样做,更新不成功,麻烦告诉下,谢谢
Hyperf\GoTask\MongoClient\Type\UpdateResult Object
(
[matchedCount:Hyperf\GoTask\MongoClient\Type\UpdateResult:private] => 0
[modifiedCount:Hyperf\GoTask\MongoClient\Type\UpdateResult:private] => 0
[upsertedCount:Hyperf\GoTask\MongoClient\Type\UpdateResult:private] => 0
[upsertedId:Hyperf\GoTask\MongoClient\Type\UpdateResult:private] =>
)
这个是打印的$result返回值
确定updateOne里面的数据是无误的
我试过用其他字段修改是成功的,但是改用 _id 之后就不行了

@Reasno
Copy link
Owner

Reasno commented Jan 5, 2021

$mongoId = '5a2493c33c95a1281836eb6a';

$collection->find(['_id'=> new MongoDB\BSON\ObjectId("$mongoId")]);

_Id 没有映射为字符串,而是映射为MongoDB\BSON\ObjectId 对象。

@Reasno Reasno closed this as completed Jan 5, 2021
@Kay-iu
Copy link
Author

Kay-iu commented Jan 5, 2021

$mongoId = '5a2493c33c95a1281836eb6a';

$collection->find(['_id'=> new MongoDB\BSON\ObjectId("$mongoId")]);

_Id 没有映射为字符串,而是映射为MongoDB\BSON\ObjectId 对象。

谢谢,按你说的,已解决

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants