所以,我用猫鼬长。
这是我的猫鼬查询代码,其中我已硬编码了有效的字符串。
const mongoose = require('mongoose');
require('mongoose-long')(mongoose);
var Long = mongoose.Types.Long;
let makertags = await Markertag.find({ 'photoId': Long.fromString('5853748089061376') });
这是我的模式:
const mongoose = require('mongoose');
require('mongoose-long')(mongoose);
const SchemaTypes = mongoose.Schema.Types;
let schema = mongoose.Schema({
photoId: { type: mongoose.Schema.Types.Long },
eventId: { type: String }
});
这是猫鼬查询调试
markertags.find({ photoId: Long { _bsontype: 'Long', low_: -277610496, high_: 1362931 } }, { fields: {} });
{
"_id" : ObjectId("5caf6e18241cb90c791157a5"),
"id" : "ahFzfnBpYzJnby1wcm9kLWhyZHIWCxIJTWFya2VyVGFnGICA0OvHkYYJDA",
"photoId" : NumberLong(4503749505843200),
"markerNum" : NumberInt(531)
}
{
"_id" : ObjectId("5caf6e18241cb90c791157a6"),
"id" : "ahFzfnBpYzJnby1wcm9kLWhyZHIWCxIJTWFya2VyVGFnGICA0LurouQIDA",
"photoId" : NumberLong(4503851813306368),
"markerNum" : NumberInt(405)
}
我不确定如何正确执行此操作,因为我不断获取空数组。
答案 0 :(得分:0)
所以,这就是我最终使用的,只需使用原始查询:D
const collection =等待mongoose.connection.db.collection('markertags'); const makertags =等待collection.find({'photoId':Long.fromString(search.searchText)})。toArray();