mongodb_ecto
mongodb_ecto copied to clipboard
in causing query to be order dependent
trafficstars
I will admit that I am not 100% that in is causing this issue, I have not dug deep enough into it.
MyApp.Repo.all(from l in MyApp.Location,
where: l.id in ^location_ids and l.company_id == ^company.id)
The following is the output from the logger from the query
FIND coll="locations" query=[{"$query", ["$and": [[_id: ["$in": [#BSON.ObjectId<578cda4955cf0a1638000001>, #BSON.ObjectId<54bd44f0946002b22a000528>, #BSON.ObjectId<58125b8e8a97fa9ce4000004>, #BSON.ObjectId<5787d39855cf0afc62000003>, #BSON.ObjectId<528b91bdf1f179db9400065c>, #BSON.ObjectId<57868f1a94600275a30001d3>, #BSON.ObjectId<55fc097694600262be001f15>, #BSON.ObjectId<58125a7b5f8524c2b800000b>, #BSON.ObjectId<5476227655cf0a12fc00006c>]]], [company_id: #BSON.ObjectId<54bd44f0946002b22a000528>]]]}, {"$orderby", %{}}] projection=%{...} []
The following is the "modified" working query
MyApp.Repo.all(from l in MyApp.Location,
where: l.company_id == ^company.id and l.id in ^location_ids)
The following is the output of the working query
FIND coll="locations" query=[{"$query", ["$and": [[company_id: #BSON.ObjectId<5283c9b5f1f179b3d5000cba>], [_id: ["$in": [#BSON.ObjectId<578cda4955cf0a1638000001>, #BSON.ObjectId<54bd44f0946002b22a000528>, #BSON.ObjectId<58125b8e8a97fa9ce4000004>, #BSON.ObjectId<5787d39855cf0afc62000003>, #BSON.ObjectId<528b91bdf1f179db9400065c>, #BSON.ObjectId<57868f1a94600275a30001d3>, #BSON.ObjectId<55fc097694600262be001f15>, #BSON.ObjectId<58125a7b5f8524c2b800000b>, #BSON.ObjectId<5476227655cf0a12fc00006c>]]]]]}, {"$orderby", %{}}] projection=%{...} []
The key part here to note is that for some reason the company_id changed between the two queries. I promise I used the same information for both queries. I feel like this is related to #104.
I'm having the same issue.
Here's my query and console output.
Report
|> where([report], report.user_id in ^user_ids)
|> where([report], report.updated_at < ^before_date)
|> Repo.all
FIND coll="report" query=[{"$query", [updated_at: ["$lt": 154999], user_id: ["$in": [154998, 154999]]]}, {"$orderby", %{}}] projection=%{_id: false, user_id: true} []
And here's the working version.
Report
|> where([report], report.updated_at < ^before_date)
|> where([report], report.user_id in ^user_ids)
|> Repo.all
FIND coll="report" query=[{"$query", [updated_at: ["$lt": #DateTime<2018-02-21 21:44:02.139998Z>], user_id: ["$in": [154995, 154996]]]}, {"$orderby", %{}}] projection=%{_id: false, user_id: true} []
For context, the user ids are from a different DB, so they're just integers.