如何在 ObjCMongoDB 中执行非 CRUD 和非基本 MongoDB 命令? [英] How to do non-CRUD and non-basic MongoDB commands in ObjCMongoDB?

查看:38
本文介绍了如何在 ObjCMongoDB 中执行非 CRUD 和非基本 MongoDB 命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ObjCMongoDB 似乎对基本 CRUD 功能有很好的记录,但对于其他 mongo 命令,则有完全没有解释.

ObjCMongoDB seems to be documented perfectly well for basic CRUD functionality, but for other mongo commands there's no explanation at all.

具体来说,我需要知道怎么做:

Specifically, I need to know how to do:

    db.collection.findAndModify()

任何帮助,一如既往,将不胜感激.

Any help, as always, would be greatly appreciated.

推荐答案

目前还没有 findAndModify 的特定接口,但您可以使用此方法调用任意数据库命令:

Right now there's not a specific interface for findAndModify, but you can invoke arbitrary database commands with this method:

-[MongoConnection runCommandWithDictionary:onDatabaseName:error:]

10gen docs for findAndModify 给出了这个示例命令:

The 10gen docs for findAndModify give this example command:

{
    findAndModify: "people",
    query: { name: "Tom", state: "active", rating: { $gt: 10 } },
    sort: { rating: 1 },
    update: { $inc: { score: 1 } }
}

如果您使用该结构创建字典并将其传递给 -runCommandWithDictionary,您应该会得到您想要的结果.

If you create a dictionary with that structure and pass it to -runCommandWithDictionary you should get the result you want.

这篇关于如何在 ObjCMongoDB 中执行非 CRUD 和非基本 MongoDB 命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆