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

Deprecation of system.namespaces in Mongo 3 #193

Open
trenton42 opened this issue Oct 11, 2016 · 9 comments
Open

Deprecation of system.namespaces in Mongo 3 #193

trenton42 opened this issue Oct 11, 2016 · 9 comments

Comments

@trenton42
Copy link
Contributor

The collection_names method uses direct access to system.namespaces, which is now deprecated in Mongo 3.0

@trenton42
Copy link
Contributor Author

I am working on a patch for this, and will PR when ready.

@IlyaSkriblovsky
Copy link
Contributor

I've added Collection._list_collections recently for the sake of Collection.options: https://github.com/twisted/txmongo/blob/master/txmongo/collection.py#L184

@trenton42
Copy link
Contributor Author

Oh! I didn't see that! Should collection_names automatically use that method if the server version supports it then?

@IlyaSkriblovsky
Copy link
Contributor

IlyaSkriblovsky commented Oct 11, 2016

Yes, you may do fallback to system.namespaces like I did in options. It seems there is no convenient way to check server version before doing query because we don't have reference to the protocol yet. Fallback on OperationFailure seems more convenient. May be it worth to check errcode in OperationFailure too to determine if it command not supported or user passed malformed filter.

@trenton42
Copy link
Contributor Author

I was just digging through the protocol docs looking for something useful, and another possibility is to use the listCommands command at connection time to configure behavior for this and possibly other commands that have become deprecated. I'm not sure if that's a good idea or not.

@trenton42
Copy link
Contributor Author

Also, how do you feel about moving _list_collections_3_0 from collection.py to database.py?

@IlyaSkriblovsky
Copy link
Contributor

IlyaSkriblovsky commented Oct 11, 2016

Also, how do you feel about moving _list_collections_3_0 from collection.py to database.py?

Sure, please do this

use the listCommands command at connection time to configure behavior

I think there is no need because we already have max_wire_version in MongoProtocol. But we might be connected to a replicaset with MongoDB instances of different versions. So, server version is only known at Protocol level, not on Database one. But you might do something like this:

def collection_names(self, **kwargs):
    def on_proto(proto):
        if proto.max_wire_version >= 3:
            # send listCommands to proto
        else:
            # send system.namespaces query to proto
    return self.connection.getprotocol().addCallback(on_proto)

But you will need to send command via the same connection, proto, so you can't just use command() or find_one() because they will get another protocol from the pool, that might have different max_wire_version. So, you will need to manually construct Query() object, send it by proto.send_QUERY and decode result. Seems not so convenient to me...

But it turns out that my approach with falling back to system.namespaces on OperationFailure is not correct too, because when falling back we might send query to system.namespaces via another connection... Doh...

@IlyaSkriblovsky
Copy link
Contributor

Seems like if we want technically correct implementation, we have to do it like described in previous post. I can't imagine any easier way that is still bulletproof :(

@trenton42
Copy link
Contributor Author

Ha, nothing is simple in the end, right?

I am half way through a prototype implementation as you described above. I will make a PR once I'm done.

Thanks for the feed back on this, you are a lot more knowledgeable on the internals of this than I am, and it's very helpful.

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