Last active
December 30, 2016 02:27
-
-
Save auser/506ba362eac529787d848b88459283ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# elixir | |
{:ok, pid} = Mongo.start(database: "test") | |
coll = "tags" | |
pipeline = [ | |
%{'$project': %{ 'b': %{ '$in': ["b", ["a", "b", "c"]] } }}, | |
%{'$match': %{ 'b': true }}, | |
%{'$project': %{ 'b': 0 }} | |
] | |
Mongo.aggregate(pid, coll, pipeline) |> Enum.to_list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in mongo cli | |
// Add some data | |
db.tags.insertMany([ | |
{ ints: [1, 2, 3], name: "numbers" }, | |
{ ints: [3, 4, 5], name: "next_numbers" }, | |
{ ints: ["a", "b", "c"], name: "letters" }, | |
]) | |
// Select on the string constant | |
db.tags.aggregate([ | |
{ $project: { "b": { $in: ["b", ["a", "b", "c"]] }}}, | |
{ $match: { b: true }}, | |
{ $project: { "b": 0 }} | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment