Skip to content

Instantly share code, notes, and snippets.

@auser
Last active December 30, 2016 02:27
Show Gist options
  • Save auser/506ba362eac529787d848b88459283ef to your computer and use it in GitHub Desktop.
Save auser/506ba362eac529787d848b88459283ef to your computer and use it in GitHub Desktop.
# 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
// 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