[英]Mongoose/mongodb find nearest match
I am currently using mongoose, with this model instructions in model called tickets 我当前正在使用猫鼬,该模型中的模型说明称为票证
Fromticket, Number default 0 Toticket, number, default 0 客票,号码默认0客票,号码默认0
Let say I have these rows: 假设我有这些行:
{fromticket:1 , toticket:3000},
fromticket:3001 , toticket:29000}
, ,
how can I find the row that contains for example the ticket is 20000? 我如何找到包含票证的行,例如20000? Or 3001? 还是3001? ( would be row number 2 in the example) (在示例中为第2行)
Tickets.find( row where owner is ticket 2000)
Each term in a query is implicitly ANDed, so you can query for the document where fromticket <= 20000
and toticket >= 20000
using: 查询中的每个术语都是隐式AND的,因此您可以使用以下方法查询fromticket <= 20000
和toticket >= 20000
的文档:
var ticket = 20000;
Tickets.findOne({
fromticket: {$lte: ticket},
toticket: {$gte: ticket}
}, (err, ticket) => {...});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.