Comments (4)
Hi @nevi-me! The issue here is that the Bson::Array
expects a Vec<Bson>
, and in this case you've provided a Vec<ObjectId>
. If you wrap each ObjectId in Bson::ObjectId
, this will work:
use bson::Bson;
use bson::oid::ObjectId;
// Note that you don't actually need to declare the type here; it will be inferred properly.
let mut ids= vec![];
for x in object_ids.iter() {
ids.push(Bson::ObjectId(ObjectId::with_string(x).unwrap()));
}
For some extra fun, here's how you could do it using iterators instead of a for loop:
use bson::Bson;
use bson::oid::ObjectId;
let ids: Vec<_> = ["5b4289600000000000000000", "5b1afc600000000000000000"]
.into_iter()
.map(|oid_string| Bson::ObjectId(
ObjectId::with_string(oid_string).unwrap()))
.collect();
from bson-rust.
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 fine! Think of it as saving time for other users in the future by categorizing them.
from bson-rust.
Thanks @saghm! Do you mind if I keep this issue open for a bit longer? I'm converting a long pipeline from the Java API, and it's using quite a lot of aggregation features, so I might still get stuck with other computer issues that I can't resolve myself.
from bson-rust.
Thanks! I know some library maintainers prefer questions that might not be bugs asked on S/O. So I'm often unsure of how to strike a balance.
from bson-rust.
Related Issues (20)
- Deserialization implementation for Document doesn't handle documents with extjson keys HOT 1
- Feature Request: Consider CompactString for Document keys HOT 1
- Number type (u16) field of struct throwing "invalid type: floating point `21010`, expected u16" HOT 2
- Use RawDocument/Buf in doc! HOT 3
- serde_with `SerializeAs` & `DeserializeAs` support for time crate HOT 2
- Add Option<ObjectId> serialize_object_id_as_hex_string support HOT 3
- Serialising and deserialising a BSON document with Regex can change the document HOT 3
- Better Details for BSON Deserialization Errors HOT 5
- use simd to optimize uft8 validation. HOT 3
- Bson fails to serialize AND deserialize IPAddr keys in hashmaps HOT 3
- `js-sys` should not be used when targeting `wasm32-wasi` HOT 3
- add ObjectId deserialization from sequence to support messagepack HOT 8
- Inconsistency between documentation and code implementation HOT 3
- RUST-1892 incorrect serialization/deserializer on big endian machines ( s390x ) HOT 5
- Serialization issue with Uuid HOT 3
- RUST-1899 Deserialization with UUID HOT 5
- How to deserialize ISO formatted json into Bson::DateTime HOT 1
- Time's "large-dates" feature should be optional HOT 1
- document has bytes remaining that were not visited HOT 4
- Operating on BSON Decimal128 type HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bson-rust.