我正在尝试编辑一个用python制作的不和谐的机器人(最初我用python存储数据),并将其传输到javascript (node.js),并且在连接到我的旧数据库时不能显示出来--为什么findOne给了我null,同时提供了适当的不和谐id。
里面没有任何东西
代码
anifarm.findOne();
输出
{
_id: 707876147324518400,
farmed: 17,
ordered: 5,
pimage: 'https://media.tenor.com/images/e830217a5d9926788ef25119955edc7f/tenor.gif',
pstatus: 'I want you to be happy. I want you to laugh a lot. I don’t know what exactly I’ll be able to do for you, but I’ll always be by your side.',
avg: 184,
speed: 2,
badges: [
'https://cdn.discordapp.com/attachments/856137319149207563/856137435696332800/Black-and-Yellow-Gaming-Badge--unscreen.gif',
'https://cdn.discordapp.com/attachments/856137319149207563/862219383866523688/Front-removebg-preview.png', 'https://cdn.discordapp.com/attachments/856137319149207563/862240758768599100/download-removebg-preview.png'
],
setBadges: 'https://cdn.discordapp.com/attachments/856137319149207563/862240758768599100/download-removebg-preview.png'
}
里面有身份证
代码
anifarm.findOne({
_id: 707876147324518400
});
输出
null
模式中的anifarm。
Decleared模式
module.exports = mongoose.model('anifarm', new mongoose.Schema({
_id: Number,
farmed: {
type: Number,
default: 0
},
ordered: {
type: Number,
default: 0
},
pimage: {
type: String,
default: ""
},
pstatus: {
type: String,
default: ""
},
avg: {
type: Number,
default: 200
},
speed: {
type: Number,
default: 2
},
badges: {
type: Array,
default: []
},
setBadges: {
type: String,
default: ""
}
},
{
collection: 'anifarm',
versionKey: false
})
);
我不知道我做错了什么。这个问题也发生在.find()中。
如果我提供id,则find中没有任何东西会发送空数组。
如果能提供一点帮助,我们将不胜感激
发布于 2022-01-02 23:10:44
对于您的问题,使用mongoose-long
来解决您的问题。
这个库将处理猫鼬的所有长类型数据,因为猫鼬不能处理长类型数据。
发布于 2021-09-07 23:07:28
不能将id作为数字传递,必须使用ObjectId
将id
转换为instanceof
ObjectId
像这样修改代码
anifarm.findOne({
_id: mongoose.Types.ObjectId(707876147324518400);
});
发布于 2021-09-07 23:24:27
https://stackoverflow.com/questions/69097339
复制相似问题