質問

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.

役に立ちましたか?

解決

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

-[MongoConnection runCommandWithDictionary:onDatabaseName:error:]

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 } }
}

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top