Giter VIP home page Giter VIP logo

Comments (4)

saghm avatar saghm commented on July 29, 2024 3

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.

saghm avatar saghm commented on July 29, 2024 1

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.

nevi-me avatar nevi-me commented on July 29, 2024

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.

nevi-me avatar nevi-me commented on July 29, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.