- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
这一定是个愚蠢的问题,但我已经把头撞在墙上已经够久了。
简短版本:我有一个查询,它在 Mongo 控制台中按预期返回结果,但在通过 Mongo NodeJS 包使用时不返回结果(或错误)。
var weatherCacheQuery = {
'location': {
'$near': {
'$geometry': {
type: 'Point',
coordinates: [location.coordinates[0], location.coordinates[1]]
},
'$maxDistance': 50000
}
},
'retrieved': {
'$gte': moment().subtract(2, 'hours').toDate()
}
};
this.db.collection('weather').findOne(
weatherCacheQuery,
function(err, doc) {
console.log(JSON.stringify(err));
console.log(JSON.stringify(doc));
}
});
如您所见,没有什么过于复杂的。
如果我转储查询对象并将其粘贴到 Mongo 控制台中的 findOne 查询中,它会返回一个看起来完全符合预期的结果。但在 JS 中,两个 console.log() 返回 null。
更奇怪的是,具有相同查询的 find() 确实返回结果,但我无法查看结果,因为 JSON.stringify() 提示它是循环的。
有人能指出我做错的无疑荒谬的事情吗?
最佳答案
.findOne
对于 Node MongoDB 驱动程序需要三个参数,并且它们似乎都不是可选的。尝试:
this.db.collection('weather').findOne(
weatherCacheQuery, {},
function(err, doc) {
console.log(JSON.stringify(err));
console.log(JSON.stringify(doc));
}
});
您还可以使用 Promise 进行尝试,将 .then
链接到 .then
并将回调传递给它。
文档还说 .findOne
已弃用并可以使用。
find().limit(1).next
您可以将回调传递给它。
关于node.js - .findOne 未将结果传递给回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33875443/
我有一个简单的 node.js 代码,它使用 mongoose,它在保存时工作但不检索。 .save() 有效,但 .findOne() 无效。 mongoose = require('mongoos
const categorySlug = req.query.category; const category = await Category.findOne({ slug: categorySlu
我正在使用 Waterline通过 Sails 查询 MySQL 数据库。我找到了 2 种方法。 不知道哪个更好? 顺便问一下,如何处理这两种情况的错误? 1. Model.findOne().whe
我可以在没有数据匹配的情况下将 findOne 查询结果从 NULL 更改为空对象吗?如果是,如何? 先感谢您 最佳答案 我认为此选项的 Sequelize 中没有插入配置。 您可以为模型访问层创建一
我将 NestJS 框架与 TypeORM 和 PostgreSQL 结合使用。假设我有一个简单的 User 实体,它只有两个属性:id 和 name @Entity() class User {
我将 NestJS 框架与 TypeORM 和 PostgreSQL 结合使用。假设我有一个简单的 User 实体,它只有两个属性:id 和 name @Entity() class User {
I'm practicing by following a React, MUI, Nodejs, CRUD project. Currently am able to get the regi
我正在尝试使用 Sequelize 和 mysql db 创建一个模型。我正在尝试发布到“/students/register”,它一直给我一个错误,说 findOne 不是一个函数。我尝试要求我的
有没有可能做findOne在mongodb中解释? 目前我已经尝试过: db.coll.findOne({query}).explain() db.collection.findOne({query}
在我的应用程序中,我尝试使用 .findOne 但出现错误。这是我的错误:- TypeError: User.findOne is not a function at Strategy._verify
我有一个 user.js 文件,用于我网站中的用户模型。这是用户架构: var UserSchema = mongoose.Schema({ username: { type:
我正在从 SQL 迁移到 MonboDB,并且我正在尝试学习基础知识。但到目前为止,我一直在努力解决一个“Select 语句” 假设我有这样的收藏 文档1 { "_id" : "id1", "
login: function (req, res) { var username = req.param('username'); var password = re
潜在客户和客户都是集合。为什么 Leads.findOne() 返回一个对象?它应该像 Customers.findOne() 那样返回一个 Document。 我使用的是 Meteor 1.2.1。
我的 mongodb 集合中的 ids 格式如下 "_id" : NumberLong("502434721406525440"), 我正在尝试执行 mongo 的 findOne 方法来检索具有
我专门使用 mongoose,尽管我认为这没有那么重要。例如,假设我有一个名为 MongoQueue 的集合,我向该队列添加了一些人。 `MongoQueue.save {function(err,
我是第一次使用 Mongodb,我遇到了一个非常奇怪的错误。我有一个“游戏”集合,但我无法使用 _id 查询对其进行搜索。 我直接在 mongo shell 上尝试,结果如下: > db.games.
我的问题是:有一组用户。我试图找到 _id=xxx 的用户是否有 somevalue > 5。 我想知道,使用 find(...).count() > 0 或 findOne(...) != null
我在使用 TypeORM 执行嵌套查找查询时遇到一些问题。这是基本代码: const { completionId } = req?.params; const user = req.
我尝试使用护照添加 Facebook 登录信息,但遇到以下错误: 类型错误:无法在 Strategy._verify 中调用未定义的方法“findOne” 我的 app.js 文件中需要 models
我是一名优秀的程序员,十分优秀!