{"action":"created","issue":{"url":"https://api.github.com/repos/zonyitoo/bson-rs/issues/96","repository_url":"https://api.github.com/repos/zonyitoo/bson-rs","labels_url":"https://api.github.com/repos/zonyitoo/bson-rs/issues/96/labels{/name}","comments_url":"https://api.github.com/repos/zonyitoo/bson-rs/issues/96/comments","events_url":"https://api.github.com/repos/zonyitoo/bson-rs/issues/96/events","html_url":"https://github.com/zonyitoo/bson-rs/issues/96","id":339518087,"node_id":"MDU6SXNzdWUzMzk1MTgwODc=","number":96,"title":"Creating an Array of ObjectID for MongoDB Aggregation","user":{"login":"nevi-me","id":1876878,"node_id":"MDQ6VXNlcjE4NzY4Nzg=","avatar_url":"https://avatars3.githubusercontent.com/u/1876878?v=4","gravatar_id":"","url":"https://api.github.com/users/nevi-me","html_url":"https://github.com/nevi-me","followers_url":"https://api.github.com/users/nevi-me/followers","following_url":"https://api.github.com/users/nevi-me/following{/other_user}","gists_url":"https://api.github.com/users/nevi-me/gists{/gist_id}","starred_url":"https://api.github.com/users/nevi-me/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nevi-me/subscriptions","organizations_url":"https://api.github.com/users/nevi-me/orgs","repos_url":"https://api.github.com/users/nevi-me/repos","events_url":"https://api.github.com/users/nevi-me/events{/privacy}","received_events_url":"https://api.github.com/users/nevi-me/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-07-09T16:19:17Z","updated_at":"2018-07-09T17:11:38Z","closed_at":null,"author_association":"NONE","body":"I'm cross-posting this here from [https://github.com/mongodb-labs/mongo-rust-driver-prototype/issues/262](https://github.com/mongodb-labs/mongo-rust-driver-prototype/issues/262) in case it's more a BSON issue\r\n\r\n___ \r\n\r\nI'm trying to convert a service from Java/Kotlin to Rust, but I'm having issues with some \"complex\" aggregation steps.\r\n\r\nI've been unable to find how to do it on both this repo and the `bson-rs` repo. Can someone help me?\r\n\r\nHow can I translate something like the below into a Rust aggregation stage?\r\n\r\n```js\r\nconst aggregationStages = [{\r\n  \"$match\": {\r\n    \"_id\": {\r\n      \"$in\": [ObjectId(\"5b4289600000000000000000\"), ObjectId(\"5b1afc600000000000000000\")]\r\n    }\r\n  },\r\n  \"$project\": {\r\n    \"_id\": 1,\r\n    \"field\": 1,\r\n    \"hours\": [\r\n      {\r\n        \"starts\": {\r\n          \"$arrayElemAt\": [\"$times.start\", 0]\r\n        }\r\n      }, \r\n      {\r\n        \"ends\": {\r\n          \"$arrayElemAt\": [\"$times.end\", -1]\r\n        }\r\n      }\r\n    ]\r\n  }\r\n}]\r\n```\r\n\r\nI suppose I don't know how to convert arrays into valid Bson documents.\r\n\r\nI tried the following, but have `<bson macros>` errors.\r\n\r\n```rust\r\n// get the colelction from the db\r\nlet coll = client.db(\"mydb\").collection(\"places\");\r\nlet mut aggregation_stages: Vec<bson::Document> = vec![];\r\nlet mut aggregation_options = mongodb::coll::options::AggregateOptions::new();\r\naggregation_options.allow_disk_use = Some(true);\r\naggregation_options.batch_size = 1000;\r\n\r\nlet object_ids = [\"5b4289600000000000000000\", \"5b1afc600000000000000000\"];\r\nlet mut ids: Vec<bson::oid::ObjectId> = vec![];\r\n\r\n  for x in object_ids.iter() {\r\n    ids.push(bson::oid::ObjectId::with_string(x).unwrap())\r\n  }\r\n\r\n    aggregation_stages.push(doc! { \"$match\": doc! { \"_id\": doc! { \"$in\": ids} }});aggregation_stages.push(doc! {\"$project\": doc! {\r\n  \"_id\" : 1,\r\n  \"other_field\" : 1,\r\n  \"hours\": [\r\n    doc! { \"starts\" : doc! {\"$arrayElemAt\" : [\"$times.start\", 0]} },\r\n    doc! { \"ends\" : doc! {\"$arrayElemAt\" : [\"$times.end\", -1]} }\r\n  ]\r\n}});\r\n```\r\n\r\nI'm getting the below error:\r\n\r\n```\r\nerror[E0277]: the trait bound `bson::Bson: std::convert::From<std::vec::Vec<bson::oid::ObjectId>>` is not satisfied\r\n   --> src\\main.rs:111:60\r\n    |\r\n111 |     aggregation_stages.push(doc! { \"$match\": doc! { \"_id\": doc! { \"$in\": ids} }});\r\n    |                                                            ^^^^^^^^^^^^^^^^^^ the trait `std::convert::From<std::vec::Vec<bson::oid::ObjectId>>` is not implemented for `bson::Bson`\r\n    |\r\n    = help: the following implementations were found:\r\n              <bson::Bson as std::convert::From<i32>>\r\n              <bson::Bson as std::convert::From<f32>>\r\n              <bson::Bson as std::convert::From<std::vec::Vec<bson::Bson>>>\r\n              <bson::Bson as std::convert::From<(bson::spec::BinarySubtype, std::vec::Vec<u8>)>>\r\n            and 16 others\r\n    = note: required by `std::convert::From::from`\r\n    = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)\r\n\r\n```"},"comment":{"url":"https://api.github.com/repos/zonyitoo/bson-rs/issues/comments/403551630","html_url":"https://github.com/zonyitoo/bson-rs/issues/96#issuecomment-403551630","issue_url":"https://api.github.com/repos/zonyitoo/bson-rs/issues/96","id":403551630,"node_id":"MDEyOklzc3VlQ29tbWVudDQwMzU1MTYzMA==","user":{"login":"saghm","id":5875560,"node_id":"MDQ6VXNlcjU4NzU1NjA=","avatar_url":"https://avatars2.githubusercontent.com/u/5875560?v=4","gravatar_id":"","url":"https://api.github.com/users/saghm","html_url":"https://github.com/saghm","followers_url":"https://api.github.com/users/saghm/followers","following_url":"https://api.github.com/users/saghm/following{/other_user}","gists_url":"https://api.github.com/users/saghm/gists{/gist_id}","starred_url":"https://api.github.com/users/saghm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saghm/subscriptions","organizations_url":"https://api.github.com/users/saghm/orgs","repos_url":"https://api.github.com/users/saghm/repos","events_url":"https://api.github.com/users/saghm/events{/privacy}","received_events_url":"https://api.github.com/users/saghm/received_events","type":"User","site_admin":false},"created_at":"2018-07-09T17:11:38Z","updated_at":"2018-07-09T17:11:38Z","author_association":"CONTRIBUTOR","body":"If you run into different issues, it's probably better to use separate issues; that way, other users who run into the same problem in the future can search for them more easily (and find the responses without having to scroll through a bunch of unrelated things). If you end up filing a bunch of issues, that's totally file; think of it as saving time for other users in the future by categorizing them."}}
{"actor":{"display_login":"saghm"}}