Giter Club home page Giter Club logo

Comments (8)

art049 avatar art049 commented on May 16, 2024 1

Hey, yes I will merge #91 as soon as possible, this should help you with the coverage :)

from odmantic.

art049 avatar art049 commented on May 16, 2024 1

Closed by #227

from odmantic.

art049 avatar art049 commented on May 16, 2024

Nice catch @Olegt0rr 🤓

In MongoDB transactions are not available for Standalone.

Do you have some references about this ?
The only transaction requirements I found were those https://docs.mongodb.com/manual/core/write-operations-atomicity/
Edit: Actually, it's stated that this would only work on replicaSets

from odmantic.

art049 avatar art049 commented on May 16, 2024

To find out if we're connected to a replicaset or not, i found another way, using the db.serverStatus command:

server_status = await self.database.command({'serverStatus'  :1})
is_standalone = "repl" not in server_status

I tried to use the _server_property you describe but I couldn't find it on my local client.
It would be probably faster to use it as it would avoid to send an extra request to the database.

from odmantic.

Olegt0rr avatar Olegt0rr commented on May 16, 2024

Do you have some references about this ?

https://docs.mongodb.com/manual/core/transactions-production-consideration/#feature-compatibility

Replica Set (4.0+) and Sharded Cluster (4.2+) support transactions.
Standalone is not listed here.
Also you can run an experiment: pass session to request and your PR tester will answer with error 😢


i found another way, using the db.serverStatus command

This way requires server admin role:
not authorized on admin to execute command

For self.client._server_property('server_type') - readWrite role is enough.
I've found it in pymongo similar solution:
https://github.com/mongodb/mongo-python-driver/blob/6b0123594aeb6d4fa618568a28cab3344c5422f0/pymongo/mongo_client.py#L1033-L1039

Also added request to MongoDB jira: https://jira.mongodb.org/browse/PYTHON-2476

from odmantic.

art049 avatar art049 commented on May 16, 2024

This way requires server admin role:
not authorized on admin to execute command

Yes 😭, I totally forgot this initial constraint.

Thanks for creating the request in Jira !
I just saw an anwser there:

Bernie Hackett added a comment - Dec 25 2020 03:30:26 PM GMT+0000
The easiest way to do what you want, with no API changes, is to call the ismaster command. If the msg field is set to "isdbgrid" you're connected to a mongos. If the setname field is set you're connected to a replica set memeber. Otherwise you're connected to a standalone.

This looks like a very good solution. We will have to check the version as well to make sure sharded cluster are 4.2+.
To add these commands in the Engine initializer, we might have to gather the event loop held by the motor client or maybe access the underlying pymongo client (I'm not sure it's doable in a clean way for this one)

from odmantic.

Olegt0rr avatar Olegt0rr commented on May 16, 2024

Seems calling self.client._server_property('server_type') still easiest way 😭

from odmantic.

Olegt0rr avatar Olegt0rr commented on May 16, 2024

Need some help to finish tests coverage

from odmantic.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.