MongoDb/php 获取集合上的最大 id 值
我想获取集合的最大 id 值。
将 mongoDb 查询转换
db.tweets.find({},{id:1}).sort({id:-1}).limit(1)
如何使用 PHP
为 Mongo 查询语言语句?我正在尝试
$db->tweets->find(
array(),
array("id"=>1)
)->sort(array("id"=> -1))->limit(1);
,但这不起作用。
I want to get the max id value on a collection.
How do I convert the mongoDb query:
db.tweets.find({},{id:1}).sort({id:-1}).limit(1)
to Mongo Query Language Statement using PHP?
I'm trying
$db->tweets->find(
array(),
array("id"=>1)
)->sort(array("id"=> -1))->limit(1);
but that doesn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我检查了这个,它对我有用:
代码中的错误是它应该是“_id”而不是“id”。另外,我希望 $db->tweets 是一个 MongoCollection 对象,并且您已经确保了这一点。希望这有帮助。
I checked this and it works for me:
The error in your code is that it should be "_id" and not "id". Also, I hope $db->tweets is a MongoCollection object and you have ensured this. Hope this helps.