Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for custom commands #9

Closed
skion opened this issue Dec 22, 2010 · 5 comments
Closed

Support for custom commands #9

skion opened this issue Dec 22, 2010 · 5 comments

Comments

@skion
Copy link

skion commented Dec 22, 2010

Is there any way to issue a custom command (like findAndModify) through public txmongo API? The only solution I found so far is via private methods:

http://pastie.org/pastes/809589

@fiorix
Copy link
Collaborator

fiorix commented Feb 25, 2011

It shouldn't be hard to implement. I'd accept a pull request with this.

@danieleapi
Copy link

I've tested the following and it seems to work. Any comment?

#!/usr/bin/env python
# coding: utf-8

import txmongo
from twisted.internet import defer, reactor

from txmongo._pymongo.son import SON

@defer.inlineCallbacks
def example():
    mongo = yield txmongo.MongoConnection()

    test = mongo.test       # `test` database
    things = test.things    # `things` collection

    # insert new document
    yield things.insert({"foo":"bar", "name":"bar_name"}, safe=True)

    # find_and_modify
    # @see: http://www.mongodb.org/display/DOCS/findAndModify+Command
    spec = SON([
        ("findAndModify", "things"),
        ("query", {"foo":"bar"}),
        ("update", {"$set": {"name": "changed_name"}}),
        ("new", True)])

    result = yield things._database["$cmd"].find_one(spec)
    print result

if __name__ == '__main__':
    example().addCallback(lambda ign: reactor.stop())
    reactor.run()

@danieleapi
Copy link

I've forked and updated here...
https://github.com/aappii/mongo-async-python-driver/commits/master
first tests are OK...

@fiorix
Copy link
Collaborator

fiorix commented Apr 1, 2011

Cool !!
Let me know when you're done so I can review the pull request and merge into master

@danieleapi
Copy link

done... hope it's ok now... previous pull request had a bug (worked only for findAndModify, not for generic commands)

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants