【问题标题】:Mongo - Does not return data when type is NumberLongMongo - 当类型为 NumberLong 时不返回数据
【发布时间】:2017-08-19 18:56:29
【问题描述】:

我正在使用 mongoose 和 nodejs 从数据库中查询数据,我在数据库中的数据如下,它具有以下 userId:

代码:

 return dbService.query(userModel, {
                        'userId': idRetrieved
                    }, {});

查询方法的实现:

 query: function (model, conditon, options) {
            console.log(conditon, options);
            return new Promise(function (resolve, reject) {
                options = options || {};

                model.find(conditon, {}, options).exec(function (error, data) {
                    if (error) {                       
                        reject(error);
                    }
                    resolve(data);
                })
            })
        }

架构

var userToSchema = dbService.createEntityDef({
            userId: {
                type: Number
            },

            firstName: {
                type: String
            },
            lastName: {
                type: String
            },
            urlPicture: {
                type: String
            }

        });

以上不返回任何数据。

【问题讨论】:

标签: node.js mongodb mongoose


【解决方案1】:

'userId' 字段的类型不是数字。你应该使用'mongoose-long' npm 模块来定义'userId' 字段的类型

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-22
    • 2021-07-16
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-29
    相关资源
    最近更新 更多