node.js - 尝试使用 findOne 查询
问题描述
有人可以帮我理解我错了什么。我正在尝试获取我的 mongodb 集合中最后记录的 ID
db.collection('task').findOne(({_id: new ObjectID}).sort('_id:: -1').limit(1), (error, task) => {
if(error){
return console.log('There is no data inside the collection')
}
})
解决方案
经过不断的尝试,我得到了这个工作
db.collection('task').findOne({}, {sort: {id: -1},limit: 1}, (error, task) => {
if(error){
return console.log('There is no data inside the collection')
}
console.log(task)
})
推荐阅读
- spring-boot - Spring boot r2dbc transactional:注释哪个方法
- java - 在 docker 容器上托管 JavaFX 项目
- meteor - 如何将 bootstrap 5 javascript 插件导入 Meteor-Svelte 项目
- css - 我可以选择 CSS 网格中的最后一列吗?
- ios - 如何在 React 本机 ios 上设置按钮不可点击
- asp.net-core - asp.net core中登录过期时的注销处理设置
- git - 在不发布的情况下激活 ADF 触发器
- reactjs - 如何禁用和灰显 ReactSelect 组件
- java - 如何从在java中返回地图的流中收集地图
- javascript - 跟随滚动但返回其主页的浮动按钮(HTML、C#.NET)