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

Stuck trying to find() #39

Closed
pepoluan opened this issue Jan 7, 2022 · 2 comments
Closed

Stuck trying to find() #39

pepoluan opened this issue Jan 7, 2022 · 2 comments

Comments

@pepoluan
Copy link

pepoluan commented Jan 7, 2022

So I have a piece of code that looks like this:

    async def cdb_find(self, db_name: str, mango: dict) -> List[Dict[str, Any]]:
        simplog = self.simplog
        config = self.config
        if self._cdb is None:
            simplog("Connecting to CouchDB")
            username = config.couchdb_database_username
            password = config.couchdb_database_password
            host = config.couchdb_database_host
            port = config.couchdb_database_port
            self._cdb = aiocouch.CouchDB(server=f"http://{host}:{port}/", user=username, password=password)
            await self._cdb.check_credentials()
        db = await self._cdb[db_name]
        simplog(f"CouchDB find in '{db_name}' for: {mango}")
        ## STUCK HERE ##
        result = [doc.data async for doc in db.find(mango)]
        simplog(f"CouchDB got results from {db_name}")
        return result

If I await on this, I got stuck after CouchDB find in ... for: ... line.

I can confirm that the host & port are correct: Doing curl http://$HOST:$PORT/_utils/ shows Fauxton replying.

Where did I go wrong with the code above?

@pepoluan
Copy link
Author

pepoluan commented Jan 7, 2022

Ahh okay. The problem is that mango in my code is {"selector": ... criteria ...}, while .find() expects the ... criteria ... part (it will internally wrap the criteria in {"selector": ...}.

So I fix this by passing just the ... criteria ... part to .find(), and now it works!

@pepoluan pepoluan closed this as completed Jan 7, 2022
@bmario
Copy link
Member

bmario commented Jan 8, 2022

Indeed, the selector parameter of find() expects selectors.

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

2 participants