Swift MongoKitten:检查ObjectId是否存在

Swift MongoKitten:检查ObjectId是否存在,swift,mongokitten,Swift,Mongokitten,如何检查集合中是否存在ObjectId? 我从mongo控制台执行以下操作: > db.collection.find({_id: ObjectId("5bb216a8475fe42644993a40")}, {_id: 1}).limit(1); 如何使用MongoKitten实现同样的功能 let mongoClient = try MongoKitten.Database("mongodb://\(username):\(password)@\(ipAddress)/\(datab

如何检查集合中是否存在ObjectId? 我从mongo控制台执行以下操作:

> db.collection.find({_id: ObjectId("5bb216a8475fe42644993a40")}, {_id: 1}).limit(1);
如何使用MongoKitten实现同样的功能

let mongoClient = try MongoKitten.Database("mongodb://\(username):\(password)@\(ipAddress)/\(database)")
let myCollection = mongoClient[collection]
let oid = try ObjectId("5bb216a8475fe42644993a41")
let document = try myCollection.findOne("_id" ==  oid)
如果ObjectId不存在,
文档
将为
nil

另外,基于文档,Mongo DB的
findOne()
方法比
find()
方法占用的资源要多得多。但是在MongoKitten的引擎盖下
findOne()
使用
find()
方法: