MongoEngine specify read preference on query
up vote
2
down vote
favorite
I am using Mongo 2.6, Pymongo 2.7.2 and Mongoengine 0.8.7. For a particular read query, I want to use the secondary of my replica set. Hence, as specified in the mongoengine documentation here I wrote my query as follows :
from pymongo.read_preferences import ReadPreference
<collection_name>.objects().read_preference(ReadPreference.SECONDARY_PREFERRED)
However, the query is always going to the primary it seems ( The logs for this query are always seen only in the primary ). Is the syntax correct? If yes, how do I verify if the secondary is being queried?
mongodb pymongo mongoengine replicaset
add a comment |
up vote
2
down vote
favorite
I am using Mongo 2.6, Pymongo 2.7.2 and Mongoengine 0.8.7. For a particular read query, I want to use the secondary of my replica set. Hence, as specified in the mongoengine documentation here I wrote my query as follows :
from pymongo.read_preferences import ReadPreference
<collection_name>.objects().read_preference(ReadPreference.SECONDARY_PREFERRED)
However, the query is always going to the primary it seems ( The logs for this query are always seen only in the primary ). Is the syntax correct? If yes, how do I verify if the secondary is being queried?
mongodb pymongo mongoengine replicaset
Could be due to this bug if you're chaining another method such as skip, limit, etc.
– Jérôme
May 12 '16 at 16:05
I am chaining it with the order_by method but my Pymongo version is 2.7.2 and the bug is in any version >= 3.0. I guess it is broken in 2.7.2 as well.
– Yahya
May 13 '16 at 7:43
The message reads "As of now, the fix only works for pymongo ver < 3.0.", so I thought both 2.7 and 3+ where affected (although differently). You may want to try without order_by, to double-check.
– Jérôme
May 13 '16 at 8:44
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I am using Mongo 2.6, Pymongo 2.7.2 and Mongoengine 0.8.7. For a particular read query, I want to use the secondary of my replica set. Hence, as specified in the mongoengine documentation here I wrote my query as follows :
from pymongo.read_preferences import ReadPreference
<collection_name>.objects().read_preference(ReadPreference.SECONDARY_PREFERRED)
However, the query is always going to the primary it seems ( The logs for this query are always seen only in the primary ). Is the syntax correct? If yes, how do I verify if the secondary is being queried?
mongodb pymongo mongoengine replicaset
I am using Mongo 2.6, Pymongo 2.7.2 and Mongoengine 0.8.7. For a particular read query, I want to use the secondary of my replica set. Hence, as specified in the mongoengine documentation here I wrote my query as follows :
from pymongo.read_preferences import ReadPreference
<collection_name>.objects().read_preference(ReadPreference.SECONDARY_PREFERRED)
However, the query is always going to the primary it seems ( The logs for this query are always seen only in the primary ). Is the syntax correct? If yes, how do I verify if the secondary is being queried?
mongodb pymongo mongoengine replicaset
mongodb pymongo mongoengine replicaset
asked May 12 '16 at 9:48
Yahya
1841617
1841617
Could be due to this bug if you're chaining another method such as skip, limit, etc.
– Jérôme
May 12 '16 at 16:05
I am chaining it with the order_by method but my Pymongo version is 2.7.2 and the bug is in any version >= 3.0. I guess it is broken in 2.7.2 as well.
– Yahya
May 13 '16 at 7:43
The message reads "As of now, the fix only works for pymongo ver < 3.0.", so I thought both 2.7 and 3+ where affected (although differently). You may want to try without order_by, to double-check.
– Jérôme
May 13 '16 at 8:44
add a comment |
Could be due to this bug if you're chaining another method such as skip, limit, etc.
– Jérôme
May 12 '16 at 16:05
I am chaining it with the order_by method but my Pymongo version is 2.7.2 and the bug is in any version >= 3.0. I guess it is broken in 2.7.2 as well.
– Yahya
May 13 '16 at 7:43
The message reads "As of now, the fix only works for pymongo ver < 3.0.", so I thought both 2.7 and 3+ where affected (although differently). You may want to try without order_by, to double-check.
– Jérôme
May 13 '16 at 8:44
Could be due to this bug if you're chaining another method such as skip, limit, etc.
– Jérôme
May 12 '16 at 16:05
Could be due to this bug if you're chaining another method such as skip, limit, etc.
– Jérôme
May 12 '16 at 16:05
I am chaining it with the order_by method but my Pymongo version is 2.7.2 and the bug is in any version >= 3.0. I guess it is broken in 2.7.2 as well.
– Yahya
May 13 '16 at 7:43
I am chaining it with the order_by method but my Pymongo version is 2.7.2 and the bug is in any version >= 3.0. I guess it is broken in 2.7.2 as well.
– Yahya
May 13 '16 at 7:43
The message reads "As of now, the fix only works for pymongo ver < 3.0.", so I thought both 2.7 and 3+ where affected (although differently). You may want to try without order_by, to double-check.
– Jérôme
May 13 '16 at 8:44
The message reads "As of now, the fix only works for pymongo ver < 3.0.", so I thought both 2.7 and 3+ where affected (although differently). You may want to try without order_by, to double-check.
– Jérôme
May 13 '16 at 8:44
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
Figured out what the issue was. In the MongoEngine "connect" method, the replicaSet parameter needed to be specified as follows:
connect(db = "my_db", replicaSet = "my_replica_set_name", host = "hostname", port = "port_number")
The syntax of the read preference is correct as specified above. Passing in the replicaSet parameter made it work.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Figured out what the issue was. In the MongoEngine "connect" method, the replicaSet parameter needed to be specified as follows:
connect(db = "my_db", replicaSet = "my_replica_set_name", host = "hostname", port = "port_number")
The syntax of the read preference is correct as specified above. Passing in the replicaSet parameter made it work.
add a comment |
up vote
1
down vote
Figured out what the issue was. In the MongoEngine "connect" method, the replicaSet parameter needed to be specified as follows:
connect(db = "my_db", replicaSet = "my_replica_set_name", host = "hostname", port = "port_number")
The syntax of the read preference is correct as specified above. Passing in the replicaSet parameter made it work.
add a comment |
up vote
1
down vote
up vote
1
down vote
Figured out what the issue was. In the MongoEngine "connect" method, the replicaSet parameter needed to be specified as follows:
connect(db = "my_db", replicaSet = "my_replica_set_name", host = "hostname", port = "port_number")
The syntax of the read preference is correct as specified above. Passing in the replicaSet parameter made it work.
Figured out what the issue was. In the MongoEngine "connect" method, the replicaSet parameter needed to be specified as follows:
connect(db = "my_db", replicaSet = "my_replica_set_name", host = "hostname", port = "port_number")
The syntax of the read preference is correct as specified above. Passing in the replicaSet parameter made it work.
answered Jul 1 '16 at 6:34
Yahya
1841617
1841617
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f37183256%2fmongoengine-specify-read-preference-on-query%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Could be due to this bug if you're chaining another method such as skip, limit, etc.
– Jérôme
May 12 '16 at 16:05
I am chaining it with the order_by method but my Pymongo version is 2.7.2 and the bug is in any version >= 3.0. I guess it is broken in 2.7.2 as well.
– Yahya
May 13 '16 at 7:43
The message reads "As of now, the fix only works for pymongo ver < 3.0.", so I thought both 2.7 and 3+ where affected (although differently). You may want to try without order_by, to double-check.
– Jérôme
May 13 '16 at 8:44