通过Mongodb中的ObjectID的一部分查询?

问题描述 投票:0回答:1
"_id" : ObjectId("5b9f472a20f7a27d8ae2ab48"),

db.getCollection('col_cost').find({_id:ObjectId("5b9f472a20f7a27d8ae2ab48")})  

如何通过调用“ e2ab48”找到此文档?

Mongodb版本3.4.2和我的收藏集https://jsoneditoronline.org/?id=c76174b321e545ba82fc2dd785ff3513我想打电话给CostId。我可以用6位数字的字符串找到这笔费用吗?

node.js mongodb objectid
1个回答
0
投票

使用$where

db.getCollection('col_cost').find({ $where: "this._id.str.match(/.*e2ab48/)" }) 
© www.soinside.com 2019 - 2024. All rights reserved.